Wayland Automation
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), and auto-click 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 (
kwinscripting via D-Bus) - XWayland (
xdotool) - Kernel input fallback (
evdev)
- Hyprland (
- Fast & Efficient — Optimized typing leveraging
wtype -dbatching 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 checkto 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
# --- 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
# 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).speedcan 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")
Waitsinitial_delay, then clicks at the current cursor position repeatedly.wa.cleanup()
Releases cached sockets and connections (automatically invoked on interpreter exit).
Keyboard Functions
wa.typewrite(text: str, interval: float = 0.0)
Types text. Ifinterval > 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 forget_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!
- Fork the repository & clone locally.
- Run unit tests before submitting changes:
python -m unittest discover tests -v
- See CONTRIBUTING.md for details.
License
Distributed under the MIT License. Copyright (c) 2025–2026 OTAKUWeBer.
Metadata
Release files for wayland-automation 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| wayland_automation-0.3.0.tar.gz | 28.6 kB | Without provenance | Details for wayland_automation-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| wayland_automation-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for wayland_automation-0.3.0-py3-none-any.whl |
Total release size: 53.8 kB
Release files / wayland_automation-0.3.0.tar.gz
| Download URL | wayland_automation-0.3.0.tar.gz |
|---|---|
| Size | 28.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ff3024fa43ad8407d8b6d7a23ba37950812e6fd1a08911683871650c58c90a85
|
|
BLAKE2b-256 checksum How to use checksums |
f7d5db5375282ec6595c6c92c7bb97689ece549a73fa0a41245dbd7a25a68945
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.15.1
|
Release files / wayland_automation-0.3.0-py3-none-any.whl
| Download URL | wayland_automation-0.3.0-py3-none-any.whl |
|---|---|
| Size | 25.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1aad84e71dfae7b008e2c08cc10152f974eeb4a5057a086b2244669fcdf001ee
|
|
BLAKE2b-256 checksum How to use checksums |
b7e773d6a175e05dffb2fb9b6ef1a7963c98320ac4fa24e8a8fee47dd808f668
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.15.1
|
Security for wayland-automation 0.3.0
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.