Skip to main content

Wayland Automation

CI PyPI version Python 3.8+ License: MIT

A lightweight, robust Python library for mouse, keyboard, and cursor automation on Wayland compositors. Designed as a modern Wayland-native alternative to PyAutoGUI.

Works out of the box on Hyprland, Sway, and other wlroots-based compositors, with native cursor position tracking on KDE Plasma (KWin).


Features

  • Mouse Control — Move, click (left, right, middle, nothing), swipe (drag), auto-click, scroll, button press and release at absolute coordinates.
  • Keyboard Automation — Type text, tap keys, hold keys down/up, and execute complex hotkeys (Ctrl+Alt+T, Ctrl+S).
  • Cursor Tracking — Real-time position generator or one-shot snapshot (get_position()) across multiple compositors:
    • Hyprland (hyprctl)
    • Sway / wlroots (wl-find-cursor)
    • KDE Plasma (kwin scripting via D-Bus)
    • XWayland (xdotool)
    • Kernel input fallback (evdev)
  • Fast & Efficient — Optimized typing leveraging wtype -d batching and automatic socket connection pooling.
  • Clean Resource Management — Context manager support (with Mouse() as mouse:), safe socket lifecycle, and no dangling file descriptors.
  • Full CLI & Diagnostics — Built-in wayland-automation check to diagnose compositors, environment variables, and missing tools in seconds.

Installation

1. Install via pip

# Standard install
pip install wayland-automation

# With KDE Plasma cursor tracking support
pip install "wayland-automation[kde]"

2. System Dependencies

Wayland's security architecture requires specific tools or protocols depending on what you want to automate:

Dependency Purpose Install Command
wtype Required for keyboard automation sudo pacman -S wtype (Arch)
sudo apt install wtype (Debian/Ubuntu)
sudo dnf install wtype (Fedora)
wayland-utils Screen resolution detection sudo pacman -S wayland-utils (Arch)
sudo apt install wayland-utils (Debian/Ubuntu)
sudo dnf install wayland-utils (Fedora)

Cursor Tracking Backends

The library automatically detects the best available backend:

Backend Compositor Requirement / Install
hyprctl Hyprland Built into Hyprland (zero configuration)
wl-find-cursor Sway / wlroots Compile from source
kwin (D-Bus) KDE Plasma pip install dbus-next (qdbus is pre-installed)
xdotool XWayland windows sudo pacman -S xdotool / sudo apt install xdotool
evdev (fallback) Generic Linux pip install evdev + add user to input group
Building wl-find-cursor from source (Sway / wlroots)
git clone https://github.com/cjacker/wl-find-cursor.git
cd wl-find-cursor
make
sudo cp wl-find-cursor /usr/local/bin/
Setting up evdev fallback permission
sudo usermod -aG input $USER
# Log out and log back in for group membership to take effect

Quick Start

Top-level Convenience API

The simplest way to automate tasks — no manual initialization needed:

import wayland_automation as wa

# --- Mouse ---
wa.click(250, 300, "left")                 # Left click at (250, 300)
wa.click(400, 500, "right")                # Right click
wa.click(600, 700, "middle")               # Middle click
wa.click(100, 100, "nothing")              # Move pointer without clicking
wa.swipe(100, 200, 800, 200, speed=0.5)    # Drag from A to B in 0.5s
wa.auto_click(initial_delay=2, interval=0.1, duration=5) # Repeated clicks
wa.scroll(4, 100, 300)                     # Scroll up 4 mouse wheel clicks at (100, 300)
wa.mouse_down("middle")                    # Press the middle mouse button
wa.mouse_down(300, 200, "left")            # Move to (300, 200) and hold down the left mouse button
wa.mouse_up(900, 100, "left")              # Move to (900, 100) and release the left mouse button

# --- Cursor Position ---
x, y = wa.get_position()                   # Single snapshot
print(f"Current cursor position: ({x}, {y})")

# --- Keyboard ---
wa.typewrite("Hello Wayland!", interval=0.05) # Type text with delay
wa.press("enter")                             # Tap Enter key
wa.hotkey("ctrl", "shift", "t")               # Key combination

Context Manager (Explicit Lifetime)

For fine-grained resource control or high-throughput mouse automation:

from wayland_automation import Mouse, Keyboard

with Mouse() as mouse:
    for x in range(100, 500, 50):
        mouse.click(x, 200, "left")

kb = Keyboard()
kb.typewrite("Done!")

Streaming Cursor Position

Monitor live mouse motion with an event generator:

from wayland_automation import mouse_position_generator

for x, y in mouse_position_generator(interval=0.1):
    print(f"Cursor: ({x}, {y})")
    # Break loop whenever needed

Command Line Interface (CLI)

The package provides a built-in wayland-automation CLI tool:

Diagnostics

Verify your compositor setup, environment variables, and installed tools:

wayland-automation check

Automation Commands

# Mouse click & move
wayland-automation click 500 300 left
wayland-automation click 500 300 nothing   # Move only

# Drag / swipe
wayland-automation swipe 100 100 600 600 --speed 1.5

# Auto-clicker
wayland-automation autoclick --delay 2.0 --interval 0.05 --duration 5.0 --button left

# Scroll
wayland-automation scroll -2 500 300

# Keyboard
wayland-automation type "Automating Wayland like a pro" --interval 0.02
wayland-automation press Return
wayland-automation hotkey ctrl alt t

# Cursor position
wayland-automation pos --once              # Print single (x, y)
wayland-automation pos --interval 0.1      # Live coordinate feed

API Reference

Mouse Functions

  • wa.click(x: int, y: int, button: str = "left")
    Moves pointer to (x, y) and optionally triggers a click. Options: "left", "right", "middle", "nothing" (move only).
  • wa.swipe(start_x: int, start_y: int, end_x: int, end_y: int, speed: Union[str, float] = "normal")
    Drags from (start_x, start_y) to (end_x, end_y). speed can be "normal" (1.0s) or seconds as a float.
  • wa.auto_click(initial_delay: float = 3.0, interval: float = 0.1, duration: float = 10.0, button: str = "left")
    Waits initial_delay, then clicks at the current cursor position repeatedly.
  • wa.scroll(clicks: int, x: Optional[int] = None, y: Optional[int] = None) Moves pointer to (x, y) if coordinates are provided. Scrolls by clicks amount. Up if clicks is positive, otherwise down.
  • wa.mouse_down(x: Optional[int] = None, y: Optional[int] = None, button: Optional[Union[str, int]] = "left") Moves pointer to (x, y) if coordinates are provided. Presses button (without releasing). Can be called with mouseDown. Buttons still held when the Mouse that pressed them is closed are released automatically. A process killed with SIGKILL skips this.
  • wa.mouse_up(x: Optional[int] = None, y: Optional[int] = None, button: Optional[Union[str, int]] = "left") Moves pointer to (x, y) if coordinates are provided. Releases button. Can be called with mouseUp.
  • wa.cleanup()
    Releases cached sockets and connections (automatically invoked on interpreter exit).

Keyboard Functions

  • wa.typewrite(text: str, interval: float = 0.0)
    Types text. If interval > 0, adds a delay between keystrokes.
  • wa.press(key: str)
    Taps (presses and releases) a single key (e.g. "enter", "escape", "tab", "backspace", "f5", "up", "down").
  • wa.keyDown(key: str)
    Holds a key down.
  • wa.keyUp(key: str)
    Releases a held key.
  • wa.hotkey(*keys: str)
    Presses modifier keys, taps non-modifiers, and safely releases modifiers in reverse order.

Cursor Tracking Functions

  • wa.get_position() -> tuple[int, int]
    Retrieves a single snapshot of the current cursor coordinate.
  • wa.position() -> tuple[int, int]
    Alias for get_position().
  • wa.mouse_position_generator(interval: float = 0.2, print_output: bool = False)
    Yields (x, y) tuples continuously.

Compositor Compatibility Matrix

Compositor Mouse Actions Keyboard Cursor Tracking Protocol / Backend
Hyprland ✅ ✅ ✅ zwlr_virtual_pointer_manager_v1 + hyprctl
Sway ✅ ✅ ✅ zwlr_virtual_pointer_manager_v1 + wl-find-cursor
Other wlroots ✅ ✅ ✅ zwlr_virtual_pointer_manager_v1 + wl-find-cursor
KDE Plasma ⏳ Planned ✅ ✅ Tracking via KWin Script + D-Bus (dbus-next); click planned via pointer-warp-v1
GNOME ❌ ✅ ⚠️ Keyboard via wtype; pointer restricted by Mutter security policy

Architecture

Wayland-automation/
├── wayland_automation/
│   ├── __init__.py           # Public API & connection lifecycle
│   ├── __main__.py           # CLI entry point & diagnostics engine
│   ├── mouse_controller.py   # Low-level Wayland socket client (zwlr_virtual_pointer)
│   ├── keyboard_controller.py# Keyboard automation via wtype
│   ├── mouse_position.py     # Multi-backend cursor position resolver
│   ├── kwin_cursor_pos.js    # KWin scripting companion for KDE Plasma
│   └── utils/
│       ├── __init__.py
│       └── screen_resolution.py # Display resolution detection across compositors
├── tests/                    # Automated test suite
├── .github/workflows/        # CI & PyPI deployment pipelines
├── pyproject.toml            # Modern PEP 517/621 build configuration
├── setup.py                  # Setuptools packaging metadata
└── MANIFEST.in               # Source distribution manifest

Contributing

Contributions and bug reports are warmly welcome!

  1. Fork the repository & clone locally.
  2. Run unit tests before submitting changes:
    python -m unittest discover tests -v
    
  3. See CONTRIBUTING.md for details.

License

Distributed under the MIT License. Copyright (c) 2025–2026 OTAKUWeBer.

Metadata

Release files for wayland-automation 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wayland-automation 0.3.1
File Size Uploaded Provenance Actions
wayland_automation-0.3.1.tar.gz 32.2 kB Without provenance Details for wayland_automation-0.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for wayland-automation 0.3.1
File Interpreter ABI Platform Actions
wayland_automation-0.3.1-py3-none-any.whl Python 3 none any Details for wayland_automation-0.3.1-py3-none-any.whl

Total release size: 60.0 kB

Release files / wayland_automation-0.3.1.tar.gz

Download URL wayland_automation-0.3.1.tar.gz
Size 32.2 kB
Tags Source
SHA-256 checksum
How to use checksums
299e144160b8681a25203a8c5d6a2574342a4720ebfeb3f2955e350c92f57e27
BLAKE2b-256 checksum
How to use checksums
3eeb64dfb7b36fa2f9b386e9bb382921d06dee12d5d29b7e95e7ca689da1369f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.2

Release files / wayland_automation-0.3.1-py3-none-any.whl

Download URL wayland_automation-0.3.1-py3-none-any.whl
Size 27.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
33b9cd0f66951d443647373e8746425f3d190d3d79ac70e75cbe0be5c208833b
BLAKE2b-256 checksum
How to use checksums
8066c3b5aad1cfdfff7fce545c130ee5e50f2099f19d819bddddbc2635a39546
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.2

Security for wayland-automation 0.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page