- Moving the Mouse: You can move the mouse cursor to specific coordinates on the screen using
pyautogui.moveTo(x, y)
. - Clicking the Mouse: You can simulate mouse clicks at specific coordinates using
pyautogui.click(x, y)
. This can be used for left, right, and middle mouse clicks. - Typing and Keyboard Actions: PyAutoGUI can simulate keyboard key presses and key combinations using functions like
pyautogui.typewrite("Hello, World!")
. - Screen Capture: You can take screenshots of the entire screen or a specific region using
pyautogui.screenshot()
. - Getting the Mouse Position: You can retrieve the current mouse cursor position using
pyautogui.position()
. - Mouse Drag and Scroll: You can simulate mouse drags (click and hold, then move) and mouse wheel scrolling using PyAutoGUI.
- Waiting and Delays: PyAutoGUI provides functions like
pyautogui.sleep()
to add delays and waits in your automation scripts. - Checking for Pixel Color: You can check the color of a pixel at a specific coordinate on the screen using
pyautogui.pixel(x, y)
.
Here’s a simple example of how to use PyAutoGUI to automate some tasks:
pythonCopy codeimport pyautogui
import time
# Move the mouse to a specific position
pyautogui.moveTo(100, 100)
# Click at the current mouse position
pyautogui.click()
# Type "Hello, PyAutoGUI!"
pyautogui.typewrite("Hello, PyAutoGUI!")
# Wait for a few seconds
time.sleep(2)
# Take a screenshot
screenshot = pyautogui.screenshot()
screenshot.save("screenshot.png")
# Check the color of a pixel at (200, 200)
pixel_color = pyautogui.pixel(200, 200)
print(f"Color at (200, 200): {pixel_color}")
Before using PyAutoGUI, make sure to install it using pip:
bashCopy codepip install pyautogui
Keep in mind that PyAutoGUI is a powerful tool for automation, but it should be used responsibly and with caution, especially when automating tasks that involve user interfaces, as it can potentially interact with unintended elements if not used carefully.