How To Automate Your Desktop With PyAutoGui

Опубликовано: 12 Январь 2022
на канале: Zack Plauché
18,160
327

Learn how to use pyautogui by following the steps below:

1. Install it: pip install pyautogui Pillow

2. Get the coordinates on your screen by running the displayMousePosition function:
```
from pyautogui import displayMousePosition
displayMousePosition()
```

3. Add those x and y coordinates to the click function:
```
from pyautogui import click
click(50, 100)
```
4. Type with your computer or press a hotkey like enter:
```
from pyautogui import click, typewrite, hotkey
click(100, 100)
typewrite('Hello world')
hotkey('enter')
```

5. Click, typewrite, and hotkey as much as you need, and put pauses where they're needed.
```
import time

from pyautogui import click, typewrite, hotkey

click(1, 100)
time.sleep(.5)
click(100, 200)
time.sleep(2)
click(200, 300)
typewrite('Hello world!')
hotkey('enter')
```

6. You can also use it in a forloop:
```
for i in range(1, 11):
click(i * 100, 200)
```

And that's it!

I've never used it outside of these 4 commands lol, so never really needed anything else.