Modules used:
In this script, we will use PyAutoGui module.
PyAutoGui module:
PyAutoGui is a Python module that will provide us various functions that helps us to control mouse and keyboard, as it is a third party module we need to install.
Download the module:
General Way to install:
pip install PyAutoGui
Pycharm Users:
Go to the project Interpreter and Install the module.
Functions provided by this module to automate the mouse,
pyautogui.size():
- This function will return us the size of the screen
- Let's store the size in a variable (let's take the variable to be the size).
- Now if we want the width of the screen then we will do.
- size[0], this will return us the screen width,
- size.width will also return the width of the screen
- size.height will return us the height of the screen.
pyautogui.moveTo(100,100,duration=0.25): This function will move your cursor to (100,100) coordinate of the screen in a time of 0.25 seconds.
pyautogui.move(100,100,duration=0.25): This function will move your cursor to the (100,100) coordinate relative to your current position.
pyautogui.position(): This function will give you the current position of your cursor.
pyautogui.click(100,100): This function will move our cursor at this coordinate and will automatically click at that position and if you didn't fill anything inside the click function then it will click at the current cursor position.
pyautogui.scroll(100): This function will scroll the screen according to the value given if positive given then it will scroll upward and if negative given then it will scroll down as it will work relative to our position(means we are at (0,0)).
Now we will create a program in which we will cover all the functions.
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer