https://github.com/enigo-rs/enigo
Cross platform input simulation in Rust
https://github.com/enigo-rs/enigo
automation cross-platform input keyboard mouse rust simulation
Last synced: 2 months ago
JSON representation
Cross platform input simulation in Rust
- Host: GitHub
- URL: https://github.com/enigo-rs/enigo
- Owner: enigo-rs
- License: mit
- Created: 2017-01-27T21:29:02.000Z (over 8 years ago)
- Default Branch: main
- Last Pushed: 2024-11-05T01:18:52.000Z (8 months ago)
- Last Synced: 2024-11-05T02:24:45.251Z (8 months ago)
- Topics: automation, cross-platform, input, keyboard, mouse, rust, simulation
- Language: Rust
- Size: 764 KB
- Stars: 1,072
- Watchers: 12
- Forks: 107
- Open Issues: 33
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/enigo-rs/enigo/actions/workflows/build.yml)
[](https://docs.rs/enigo)
[](https://deps.rs/repo/github/enigo-rs/enigo)
[](https://crates.io/crates/enigo)# enigo
Cross platform input simulation in Rust!
- [x] Serialize/Deserialize
- [x] Linux (X11) mouse
- [x] Linux (X11) text
- [x] Linux (Wayland) mouse (Experimental)
- [x] Linux (Wayland) text (Experimental)
- [x] Linux (libei) mouse (Experimental)
- [x] Linux (libei) text (Experimental)
- [x] MacOS mouse
- [x] MacOS text
- [x] Windows mouse
- [x] Windows textEnigo also works on *BSDs if they use X11 or Wayland. I don't have a machine to test it and there are no Github Action runners for it, so the BSD support is not explicitly listed.
```Rust
let mut enigo = Enigo::new(&Settings::default()).unwrap();enigo.move_mouse(500, 200, Abs).unwrap();
enigo.button(Button::Left, Click).unwrap();
enigo.text("Hello World! here is a lot of text ❤️").unwrap();
```For more, look at the ([examples](examples)).
## Features
By default, enigo currently works on Windows, macOS and Linux (X11). If you want to be able to serialize and deserialize commands for enigo ([example](examples/serde.rs)), you need to activate the `serde` feature.
There are multiple ways how to simulate input on Linux and not all systems support everything. Enigo can also use wayland protocols and libei to simulate input but there are currently some bugs with it. That is why they are hidden behind feature flags.
If you do not want your users to have to install any runtime dependencies on Linux when using X11, you can try the experimental `x11rb` feature.
## Runtime dependencies
Linux users may have to install `libxdo-dev` if they are using `X11`. For example, on Debian-based distros:
```Bash
apt install libxdo-dev
```On Arch:
```Bash
pacman -S xdotool
```On Fedora:
```Bash
dnf install libX11-devel libxdo-devel
```On Gentoo:
```Bash
emerge -a xdotool
```## Permissions
Some platforms have security measures in place to prevent programs from entering keys or controlling the mouse. Have a look at the [permissions](Permissions.md) documentation to see what you need to do to allow it.
## Migrating from a previous version
Please have a look at our [changelog](CHANGES.md) to find out what you have to do, if you used a previous version.
## Debugging
If you encounter an issue and want to debug it, turn on log messages as described [here](DEBUGGING.md).
## Testing this crate
*Warning*: The tests will move the mouse, enter text, press keys and open some applications. Read the test cases before you run them so you know what to expect. It's best to close everything so that the tests don't mess with your system. Some of them run for a long time because they are intended to be run in the CI. Make sure to run the tests sequentially, otherwise they will fail because other mouse movements or entered keys are detected. You can do so by running
```Bash
cargo test --all-features -- --test-threads=1
```