Cross-platform GUI automation library that enables programmatic control of mouse, keyboard, and screen interactions.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Complete mouse automation functionality including clicking, movement, dragging, and scrolling operations with smooth animations and configurable timing. All mouse functions support coordinate specification, duration control, and easing functions for natural movement.
Perform mouse clicks at specified coordinates with configurable button, click count, and timing options.
def click(x=None, y=None, clicks=1, interval=0.0, button='left', duration=0.0, tween=linear, logScreenshot=None, _pause=True):
"""
Perform mouse click at specified coordinates.
Parameters:
- x, y (int): Screen coordinates. If None, uses current mouse position
- clicks (int): Number of clicks to perform (default: 1)
- interval (float): Seconds between clicks for multiple clicks (default: 0.0)
- button (str): Mouse button - 'left', 'right', 'middle', 'primary', 'secondary' (default: 'left')
- duration (float): Time to move to position in seconds (default: 0.0)
- tween (function): Easing function for movement animation (default: linear)
- logScreenshot (bool): Log screenshot for debugging (default: None)
- _pause (bool): Apply global PAUSE after operation (default: True)
Returns:
None
"""
def leftClick(x=None, y=None, interval=0.0, duration=0.0, tween=linear, logScreenshot=None, _pause=True):
"""Left mouse button click. Equivalent to click() with button='left'."""
def rightClick(x=None, y=None, interval=0.0, duration=0.0, tween=linear, logScreenshot=None, _pause=True):
"""Right mouse button click. Equivalent to click() with button='right'."""
def middleClick(x=None, y=None, interval=0.0, duration=0.0, tween=linear, logScreenshot=None, _pause=True):
"""Middle mouse button click. Equivalent to click() with button='middle'."""Perform double-clicks and triple-clicks with customizable timing and button selection.
def doubleClick(x=None, y=None, interval=0.0, button='left', duration=0.0, tween=linear, logScreenshot=None, _pause=True):
"""
Perform double-click at specified coordinates.
Parameters:
- x, y (int): Screen coordinates. If None, uses current mouse position
- interval (float): Seconds between the two clicks (default: 0.0)
- button (str): Mouse button to use (default: 'left')
- duration (float): Time to move to position in seconds (default: 0.0)
- tween (function): Easing function for movement animation (default: linear)
- logScreenshot (bool): Log screenshot for debugging (default: None)
- _pause (bool): Apply global PAUSE after operation (default: True)
Returns:
None
"""
def tripleClick(x=None, y=None, interval=0.0, button='left', duration=0.0, tween=linear, logScreenshot=None, _pause=True):
"""
Perform triple-click at specified coordinates.
Parameters:
- x, y (int): Screen coordinates. If None, uses current mouse position
- interval (float): Seconds between clicks (default: 0.0)
- button (str): Mouse button to use (default: 'left')
- duration (float): Time to move to position in seconds (default: 0.0)
- tween (function): Easing function for movement animation (default: linear)
- logScreenshot (bool): Log screenshot for debugging (default: None)
- _pause (bool): Apply global PAUSE after operation (default: True)
Returns:
None
"""Control mouse button press and release states independently for complex interactions.
def mouseDown(x=None, y=None, button='left', duration=0.0, tween=linear, logScreenshot=None, _pause=True):
"""
Press mouse button down (without releasing).
Parameters:
- x, y (int): Screen coordinates. If None, uses current mouse position
- button (str): Mouse button to press - 'left', 'right', 'middle', 'primary', 'secondary' (default: 'left')
- duration (float): Time to move to position in seconds (default: 0.0)
- tween (function): Easing function for movement animation (default: linear)
- logScreenshot (bool): Log screenshot for debugging (default: None)
- _pause (bool): Apply global PAUSE after operation (default: True)
Returns:
None
"""
def mouseUp(x=None, y=None, button='left', duration=0.0, tween=linear, logScreenshot=None, _pause=True):
"""
Release mouse button (without pressing).
Parameters:
- x, y (int): Screen coordinates. If None, uses current mouse position
- button (str): Mouse button to release - 'left', 'right', 'middle', 'primary', 'secondary' (default: 'left')
- duration (float): Time to move to position in seconds (default: 0.0)
- tween (function): Easing function for movement animation (default: linear)
- logScreenshot (bool): Log screenshot for debugging (default: None)
- _pause (bool): Apply global PAUSE after operation (default: True)
Returns:
None
"""Move mouse cursor to absolute or relative positions with smooth animation support.
def moveTo(x, y, duration=0.0, tween=linear, logScreenshot=False, _pause=True):
"""
Move mouse to absolute screen coordinates.
Parameters:
- x, y (int): Target screen coordinates
- duration (float): Time to complete movement in seconds (default: 0.0 for instant)
- tween (function): Easing function for smooth animation (default: linear)
- logScreenshot (bool): Log screenshot for debugging (default: False)
- _pause (bool): Apply global PAUSE after operation (default: True)
Returns:
None
"""
def moveRel(xOffset, yOffset, duration=0.0, tween=linear, logScreenshot=False, _pause=True):
"""
Move mouse relative to current position.
Parameters:
- xOffset, yOffset (int): Relative movement distances in pixels
- duration (float): Time to complete movement in seconds (default: 0.0)
- tween (function): Easing function for smooth animation (default: linear)
- logScreenshot (bool): Log screenshot for debugging (default: False)
- _pause (bool): Apply global PAUSE after operation (default: True)
Returns:
None
"""
def move(xOffset, yOffset, duration=0.0, tween=linear, logScreenshot=False, _pause=True):
"""Alias for moveRel() - move mouse relative to current position."""Drag operations that combine mouse button press, movement, and release for drag-and-drop functionality.
def dragTo(x, y, duration=0.0, tween=linear, button='left', logScreenshot=None, _pause=True, mouseDownUp=True):
"""
Drag from current position to absolute coordinates.
Parameters:
- x, y (int): Target screen coordinates
- duration (float): Time to complete drag in seconds (default: 0.0)
- tween (function): Easing function for smooth movement (default: linear)
- button (str): Mouse button to use for dragging (default: 'left')
- logScreenshot (bool): Log screenshot for debugging (default: None)
- _pause (bool): Apply global PAUSE after operation (default: True)
- mouseDownUp (bool): Whether to press/release button automatically (default: True)
Returns:
None
"""
def dragRel(xOffset, yOffset, duration=0.0, tween=linear, button='left', logScreenshot=None, _pause=True, mouseDownUp=True):
"""
Drag relative to current position.
Parameters:
- xOffset, yOffset (int): Relative drag distances in pixels
- duration (float): Time to complete drag in seconds (default: 0.0)
- tween (function): Easing function for smooth movement (default: linear)
- button (str): Mouse button to use for dragging (default: 'left')
- logScreenshot (bool): Log screenshot for debugging (default: None)
- _pause (bool): Apply global PAUSE after operation (default: True)
- mouseDownUp (bool): Whether to press/release button automatically (default: True)
Returns:
None
"""
def drag(xOffset, yOffset, duration=0.0, tween=linear, button='left', logScreenshot=None, _pause=True, mouseDownUp=True):
"""Alias for dragRel() - drag relative to current position."""Scroll mouse wheel vertically and horizontally (platform-dependent).
def scroll(clicks, x=None, y=None, logScreenshot=None, _pause=True):
"""
Scroll mouse wheel at specified position.
Parameters:
- clicks (int): Number of scroll clicks. Positive for up/right, negative for down/left
- x, y (int): Screen coordinates to center scroll. If None, uses current position
- logScreenshot (bool): Log screenshot for debugging (default: None)
- _pause (bool): Apply global PAUSE after operation (default: True)
Returns:
None
Note: Direction depends on platform. On Windows/Mac this is vertical.
On Linux, use vscroll() or hscroll() for explicit direction control.
"""
def vscroll(clicks, x=None, y=None, logScreenshot=None, _pause=True):
"""
Vertical scroll (Linux only).
Parameters:
- clicks (int): Number of scroll clicks. Positive for up, negative for down
- x, y (int): Screen coordinates to center scroll. If None, uses current position
- logScreenshot (bool): Log screenshot for debugging (default: None)
- _pause (bool): Apply global PAUSE after operation (default: True)
Returns:
None
"""
def hscroll(clicks, x=None, y=None, logScreenshot=None, _pause=True):
"""
Horizontal scroll (Linux only).
Parameters:
- clicks (int): Number of scroll clicks. Positive for right, negative for left
- x, y (int): Screen coordinates to center scroll. If None, uses current position
- logScreenshot (bool): Log screenshot for debugging (default: None)
- _pause (bool): Apply global PAUSE after operation (default: True)
Returns:
None
"""import pyautogui
# Basic clicking
pyautogui.click(100, 200) # Click at coordinates
pyautogui.rightClick() # Right-click at current position
pyautogui.doubleClick(150, 300, interval=0.1) # Double-click with timing
# Smooth movement with animation
pyautogui.moveTo(500, 500, duration=2.0, tween=pyautogui.easeInOutQuad)
# Dragging operations
pyautogui.dragTo(400, 300, duration=1.0) # Drag to absolute position
pyautogui.dragRel(100, 0, duration=0.5) # Drag 100 pixels right
# Scrolling
pyautogui.scroll(3) # Scroll up 3 clicks
pyautogui.scroll(-2, 300, 400) # Scroll down 2 clicks at position
# Complex mouse operations
pyautogui.mouseDown(button='left') # Press and hold
pyautogui.moveTo(200, 200, duration=1.0) # Move while holding
pyautogui.mouseUp() # Release buttonLEFT: str = 'left'
RIGHT: str = 'right'
MIDDLE: str = 'middle'
PRIMARY: str = 'primary' # Usually left button
SECONDARY: str = 'secondary' # Usually right buttonInstall with Tessl CLI
npx tessl i tessl/pypi-pyautogui