Overview
PyAutoGUI is a cross-platform GUI automation module for Python. It allows you to control the mouse and keyboard, perform image recognition, and automate repetitive tasks across different applications and operating systems.
Key features
- Programmatically control the mouse and keyboard
- Perform screen capture and image recognition
- Automate repetitive GUI tasks
- Cross-platform support for macOS, Windows, and Linux
- Simple API for ease of use
Common use cases
- Automating data entry tasks
- Testing applications by simulating user inputs
- Creating scripts to control applications
- Generating automated reports using screenshots
Installation
pip install pyautogui
Example
import pyautogui
import time
# Get screen resolution
screen_width, screen_height = pyautogui.size()
# Move the mouse to the center of the screen
pyautogui.moveTo(screen_width / 2, screen_height / 2, duration=1)
# Click the mouse
pyautogui.click()
# Enter text
pyautogui.typewrite('Hello, world!', interval=0.1)
# Take a screenshot
screenshot = pyautogui.screenshot()
screenshot.save("screenshot.png")