PyAutoGUI

0.9.54 · active · verified Fri Apr 10

PyAutoGUI is a cross-platform Python library for GUI automation, enabling programmatic control of the mouse and keyboard, and other GUI tasks like screenshots and image recognition. It simplifies complex operating system interactions into a straightforward API. Currently at version 0.9.54, the library is actively maintained with updates released periodically.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates basic PyAutoGUI functions: getting screen dimensions, moving the mouse, clicking, typing text, and displaying a message box. The `duration` and `interval` parameters add human-like delays.

import pyautogui
import time

# Get screen size
screenWidth, screenHeight = pyautogui.size()
print(f"Screen size: {screenWidth}x{screenHeight}")

# Move mouse to center of screen
pyautogui.moveTo(screenWidth / 2, screenHeight / 2, duration=1)

# Click at current position
pyautogui.click()

# Type a message (simulates keyboard input)
pyautogui.write('Hello, PyAutoGUI!', interval=0.1)

# Press a hotkey combination (e.g., Ctrl+S to save)
# pyautogui.hotkey('ctrl', 's')

# Display an alert box
pyautogui.alert('Automation script finished!\nClick OK to exit.')

view raw JSON →