enigo
Cross-platform keyboard and mouse input simulation for Rust on Linux, macOS, and Windows.
Repository Health
Technical Analysis
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
Enigostruct implementing theKeyboardandMousetraits 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
agentmodule
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.
Used by 2 apps in this directory
Epicenter
Knowledge Management · Note Taking · Developer Tools
A local-first monorepo led by Whispering, an open-source speech-to-text app, built on an MIT toolkit that turns your data into plain Markdown and SQLite files you own instead of a database you rent.
Handy
Productivity
Free, offline, open-source speech-to-text that pastes directly into any app on Windows, macOS, and Linux.