Expand description
Enigo lets you simulate mouse and keyboard input-events as if they were made by the actual hardware. It is available on Linux (X11), macOS and Windows.
It can be used for testing user interfaces on different platforms, building remote control applications or just automating tasks for user interfaces unaccessible by a public API or scripting language.
This library is in an early alpha status, the API will change in in the future.
In order to use the library, you only have to know about three things:
Keyboard
(trait): used to simulate a key click, enter text or something similarMouse
(trait): do something with the mouse or you find out the display sizeEnigo
(struct): implements the two traitsKeyboard
andMouse
This crate previously included a simple DSL. This is no longer the case. In order to simplify the codebase and also allow serializing objects, you can now serialize and deserialize most enums and structs of this crate. You can use this instead of the DSL. This feature is hidden behind the serde
feature. Have a look at the serde
example to see how to use it to serialize Tokens in the RON format.
§Examples
use enigo::{
Button, Coordinate,
Direction::{Click, Press, Release},
Enigo, Key, Keyboard, Mouse, Settings,
};
let mut enigo = Enigo::new(&Settings::default()).unwrap();
// Paste
enigo.key(Key::Control, Press);
enigo.key(Key::Unicode('v'), Click);
enigo.key(Key::Control, Release);
// Do things with the mouse
enigo.move_mouse(500, 200, Coordinate::Abs);
enigo.button(Button::Left, Press);
enigo.move_mouse(100, 100, Coordinate::Rel);
enigo.button(Button::Left, Release);
// Enter text
enigo.text("hello world");
Modules§
- agent
- This crate contains the
crate::agent::Token
struct and thecrate::agent::Agent
trait. A token is an instruction for theEnigo
struct to do something. If you want Enigo to simulate input, you then have to tell the enigo struct tocrate::agent::Agent::execute
the token. Have a look at theserde
example if you’d like to read some code to see how it works.
Structs§
Enums§
- Axis
- Specifies the axis for scrolling
- Button
- Represents a mouse button and is used in e.g
Mouse::button
. - Coordinate
- Specifies if a coordinate is relative or absolute
- Direction
- The direction of a key or button
- Input
Error - Error when simulating input
- Key
- Contains the available keycodes
Use
Key::Unicode
to enter arbitrary Unicode chars. If a key is missing, please open an issue in our repo and we will quickly add it. In the mean time, you can simulate that key by usingKey::Other
or thecrate::Keyboard::raw
function. Some of the keys are only available on a specific platform. Use conditional compilation to use them. - NewCon
Error - Error when establishing a new connection
Constants§
- EVENT_
MARKER - Arbitrary value to be able to distinguish events created by enigo
Traits§
- Keyboard
- Contains functions to simulate key presses/releases and to input text.
- Mouse
- Contains functions to control the mouse and to get the size of the display. Enigo uses a cartesian coordinate system for specifying coordinates. The origin in this system is located in the top-left corner of the current screen, with positive values extending along the axes down and to the right of the origin point and it is measured in pixels. The same coordinate system is used on all operating systems.