Skip to main content

A tool for automating Wayland tasks using system packages wtype and wayland-info

Project description

Wayland Automation

A lightweight Python tool for automating pointer and keyboard actions on Wayland. This project allows you to perform basic clicks, swipes, auto-clicks, and keyboard actions using virtual devices in your Wayland environment.


Features

Pointer Automation (Mouse)

  • Basic Click:
    Move the pointer to a specified (x, y) coordinate and optionally perform a click (left or right).

  • Swipe:
    Simulate a drag gesture by swiping from one coordinate to another, with a customizable speed.

  • Auto-Click:
    Wait for a configurable delay, then repeatedly click at the current pointer position for a set duration at defined intervals.

Keyboard Automation

  • Typewrite:
    Type out a string with an optional delay between each character.

  • Press:
    Simulate a single key press (key down then key up).

  • Hotkey:
    Simulate key combinations (e.g., Ctrl+A).


Requirements

  • Python 3.x

  • Wayland Environment:
    Ensure you are running a Wayland session.

  • System Dependencies:
    This project relies on the following system-level utilities, which are not available via PyPI:

    • wayland-info: Used to obtain your screen resolution.

      • Installation:
        • Debian/Ubuntu:
          sudo apt install wayland-utils
          
        • Arch Linux:
          sudo pacman -S wayland-utils
          
    • wtype: Used for simulating keyboard actions.

      • Installation
        • Debian/Ubuntu:
          sudo apt install wtype
          
        • Arch Linux:
          sudo pacman -S wtype
          

Installation

Install via PyPI

The package is available on PyPI and can be installed using:

pip install wayland-automation

Install from Source

  1. Clone the Repository:

    git clone https://github.com/OTAKUWeBer/Wayland-automation.git
    cd Wayland-automation
    
  2. (Optional) Create a Virtual Environment:

    python3 -m venv venv
    source venv/bin/activate
    
  3. Install System Dependencies:
    Ensure that both wayland-info and wtype are installed and available in your system's PATH as described above.

  4. Install the Python Package:

    pip install .
    

    For development, consider using an editable install:

    pip install -e .
    

Usage

Pointer Automation (Mouse)

The pointer automation is handled by mouse_controller.py.

Basic Click (Python API)

Move the pointer to (x, y) and optionally perform a click.

from wayland_automation.mouse_controller import Mouse

mouse = Mouse()
mouse.click(100, 200, button="left")  # Perform a left click

Swipe (Drag)

Simulate a swipe (drag) gesture from one coordinate to another.

mouse.swipe(100, 200, 400, 500, speed=1.5)

Auto-Click

Automatically click at the current pointer position repeatedly.

mouse.auto_click(initial_delay=2, interval=0.2, duration=15, button="right")

Example: Track Mouse Position

from wayland_automation import mouse_position_generator

# Continuously track mouse position
for x, y in mouse_position_generator():
    print(f"Mouse is at: ({x}, {y})")

Keyboard Automation (Python API)

from wayland_automation.keyboard_controller import Keyboard
import time

kb = Keyboard()
time.sleep(2)  # Gives time to switch to another window

kb.typewrite("Hello, Wayland!", interval=0.05)
kb.press("enter")
kb.hotkey("ctrl", "a")

How It Works

  1. Virtual Device Initialization:
    The scripts connect to the Wayland server via a Unix socket and initialize virtual devices (pointer and keyboard) using the Wayland protocol.

  2. Message Protocol:
    Low-level Wayland messages are sent to move the pointer, simulate button events, and emulate keyboard actions via wtype.

  3. Screen Resolution:
    A helper script in the utils directory uses wayland-info to retrieve your current screen resolution, ensuring accurate pointer positioning.

  4. Modes Implementation:

    • Pointer Modes:
      Click, swipe, and auto-click actions are implemented by sending sequences of Wayland messages.
    • Keyboard Mode:
      The keyboard module supports text entry, single key presses, and hotkey combinations.

Contributing

Contributions, bug reports, and feature requests are welcome. Please open an issue or submit a pull request on the GitHub repository.


Acknowledgements

Special thanks to Zai-Kun for the foundational work on Wayland communication mechanisms that inspired this project.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wayland_automation-0.2.0.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wayland_automation-0.2.0-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file wayland_automation-0.2.0.tar.gz.

File metadata

  • Download URL: wayland_automation-0.2.0.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for wayland_automation-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ca9cd244f095fe3be2d20527a3ffb2a6c796b1da3844faa963b5cd9018e92e4c
MD5 33a4dc41492d52077d7fa6b8a1ec829d
BLAKE2b-256 2dde17c0e1e9d21a255a3ef9cd09cd91738c24a927d12b64bbc6b7990575b161

See more details on using hashes here.

File details

Details for the file wayland_automation-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for wayland_automation-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dec5e4ef024055fbfbd5228a5523b961b4695b8256bd955a3e9450ea87d3f356
MD5 7e23dcf67832035c1cb2a297fd089f3d
BLAKE2b-256 69a4a260675b5a6b600b78a5fcda5c1b154acf9eb87c663cef5256beca9651cf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page