enigo

Cross-platform keyboard and mouse input simulation for Rust on Linux, macOS, and Windows.

Library
Cargo
v0.6.1
1,772stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
75/100Good
Development Activity92
Maintenance52
Community56
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
85/100Excellent
Architecture86
Code Quality82
Innovation85
Learning Curve78

Enigo is a cross-platform Rust library that simulates mouse and keyboard input as if it came from real hardware. Through two small traits, Keyboard and Mouse, both implemented by a single Enigo struct, you can move and click the mouse, scroll, press keys, and type Unicode text with just a few lines of code.

It runs on Linux (X11, with experimental Wayland and libei backends), macOS, and Windows, hiding each platform’s native input APIs behind one consistent interface. This makes it a practical building block for UI test automation, remote-control applications, and scripting tasks against interfaces that expose no public API.

What You Get

  • A single Enigo struct implementing the Keyboard and Mouse traits for all supported platforms
  • Absolute and relative mouse movement, button clicks, and scrolling on both axes
  • Key press/release/click control plus direct Unicode text entry
  • Optional serde support to serialize and deserialize input tokens (e.g. in RON) via the agent module

Common Use Cases

  • Automating end-to-end UI tests that need real keyboard and mouse events
  • Building remote-control or screen-sharing tools that inject input
  • Scripting repetitive desktop tasks for applications without a public API or scripting layer

Under The Hood

Architecture

The public surface in src/lib.rs defines the Keyboard and Mouse traits plus shared enums (Button, Key, Direction, Coordinate, Axis) and the InputResult error type. The concrete Enigo struct is selected at compile time through cfg_attr path attributes that swap the platform module between src/linux/mod.rs, src/macos/mod.rs, and src/win/mod.rs, so a single import resolves to the correct native implementation. The agent module layers a serializable Token enum and Agent::execute on top, letting callers script and replay input.

Tech Stack

Written in Rust (edition 2024, rust-version 1.87) with platform-conditional dependencies: the windows crate for Win32 input on Windows; core-graphics, objc2, and related Apple bindings on macOS; and x11rb, wayland-client, libc, xkbcommon, and optionally reis/ashpd for the various Linux backends. Cargo feature flags (x11rb default, plus wayland, libei, xdo, serde) gate each backend and keep the dependency graph lean.

Code Quality

The crate enables #![deny(clippy::pedantic)] and carries both unit tests under src/tests/ (keyboard and mouse) and a serde-gated integration test (tests/integration_browser.rs) that verifies synthesized events against a browser. Errors are surfaced through a dedicated InputResult/error enum rather than panics, and logging via the log crate aids debugging.

API Design

The API is deliberately small: users learn three things — the Keyboard trait, the Mouse trait, and the Enigo struct built from Settings::default(). Typical operations (move_mouse, button, key, text) read as plain method calls, and Unicode text entry avoids manual keycode work. Documentation is published on docs.rs and reinforced by eight runnable examples plus dedicated Permissions and Debugging guides, keeping the onboarding cost low.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search