Cross-platform GUI automation library that enables programmatic control of mouse, keyboard, and screen interactions.
npx @tessl/cli install tessl/pypi-pyautogui@0.9.0A cross-platform GUI automation library that enables programmatic control of mouse movements, clicks, keyboard input, and screen interactions across Windows, macOS, and Linux operating systems. PyAutoGUI provides a unified API for performing GUI automation tasks including mouse positioning and clicking, keyboard input simulation, screenshot capture and image recognition, message box displays, and window management operations.
pip install pyautoguiimport pyautoguiAll functions and constants are available directly from the main module:
# Common import pattern
import pyautogui
# Access all functions directly
pyautogui.click(100, 200)
pyautogui.typewrite('Hello World')
pyautogui.screenshot()import pyautogui
import time
# Configure failsafe (move mouse to top-left corner to abort)
pyautogui.FAILSAFE = True
pyautogui.PAUSE = 1 # 1 second pause between actions
# Get screen size
screen_width, screen_height = pyautogui.size()
print(f"Screen size: {screen_width}x{screen_height}")
# Mouse operations
pyautogui.click(100, 200) # Click at coordinates
pyautogui.rightClick(300, 400) # Right-click
pyautogui.doubleClick(150, 250) # Double-click
# Keyboard operations
pyautogui.typewrite('Hello, World!') # Type text
pyautogui.press('enter') # Press a key
pyautogui.hotkey('ctrl', 'c') # Keyboard shortcut
# Screen capture and image recognition
screenshot = pyautogui.screenshot()
button_location = pyautogui.locateOnScreen('button.png')
if button_location:
pyautogui.click(button_location)
# Message boxes
pyautogui.alert('Task completed!')
response = pyautogui.confirm('Continue?', buttons=['Yes', 'No'])PyAutoGUI uses platform-specific implementations to provide a unified API:
# Global pause between operations (seconds)
PAUSE: float = 0.1
# Failsafe mechanism - move mouse to corner to abort
FAILSAFE: bool = True
# Minimum duration for mouse movements
MINIMUM_DURATION: float = 0.1
# Screenshot logging for debugging
LOG_SCREENSHOTS: bool = False
LOG_SCREENSHOTS_LIMIT: int = 10class PyAutoGUIException(Exception):
"""Base exception for PyAutoGUI errors"""
class FailSafeException(PyAutoGUIException):
"""Raised when failsafe mechanism is triggered"""
class ImageNotFoundException(PyAutoGUIException):
"""Raised when image cannot be found on screen"""Complete mouse automation including clicking, movement, dragging, and scrolling operations with smooth animations and configurable timing.
def click(x=None, y=None, clicks=1, interval=0.0, button='left', duration=0.0, tween=linear): ...
def moveTo(x, y, duration=0.0, tween=linear): ...
def dragTo(x, y, duration=0.0, tween=linear, button='left'): ...
def scroll(clicks, x=None, y=None): ...Comprehensive keyboard automation including key presses, text typing, and keyboard shortcuts with support for all standard keys and modifiers.
def press(keys, presses=1, interval=0.0): ...
def typewrite(message, interval=0.0): ...
def hotkey(*args): ...
def keyDown(key): ...
def keyUp(key): ...Screenshot capture and computer vision capabilities for finding images, text, and UI elements on screen with pixel-perfect matching and tolerance controls.
def screenshot(imageFilename=None, region=None): ...
def locateOnScreen(image, **kwargs): ...
def locateAllOnScreen(image, **kwargs): ...
def pixel(x, y): ...
def pixelMatchesColor(x, y, expectedRGBColor, tolerance=0): ...Cross-platform dialog boxes for user interaction including alerts, confirmations, text input, and password prompts.
def alert(text, title, button='OK'): ...
def confirm(text, title, buttons=['Cancel', 'OK']): ...
def prompt(text, title, default=''): ...
def password(text, title, default='', mask='*'): ...Window control and management operations for finding, manipulating, and interacting with application windows (Windows platform only).
def getActiveWindow(): ...
def getWindowsWithTitle(title): ...
def getAllWindows(): ...
class Window: ...Helper functions for debugging, system information, timing controls, and animation easing functions.
def size(): ...
def position(): ...
def onScreen(x, y): ...
def displayMousePosition(): ...
def getInfo(): ...
def sleep(seconds): ...from typing import Tuple, List, Optional, Union, Callable
from collections import namedtuple
# Coordinate and size types
Point = namedtuple('Point', ['x', 'y'])
Size = namedtuple('Size', ['width', 'height'])
# Color type (RGB tuple)
Color = Tuple[int, int, int]
# Region type (x, y, width, height)
Region = Tuple[int, int, int, int]
# Mouse button constants
LEFT: str = 'left'
RIGHT: str = 'right'
MIDDLE: str = 'middle'
PRIMARY: str = 'primary'
SECONDARY: str = 'secondary'
# Tween function type
TweenFunction = Callable[[float], float]