Crate enigo

source ·
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 similar
  • Mouse (trait): do something with the mouse or you find out the display size
  • Enigo (struct): implements the two traits Keyboard and Mouse

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§

Structs§

  • Settings for creating the Enigo struct and it’s behavior

Enums§

  • Specifies the axis for scrolling
  • Represents a mouse button and is used in e.g Mouse::button.
  • Specifies if a coordinate is relative or absolute
  • The direction of a key or button
  • Error when simulating input
  • 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 using Key::Other or the crate::Keyboard::raw function. Some of the keys are only available on a specific platform. Use conditional compilation to use them.
  • Error when establishing a new connection

Traits§

  • Contains functions to simulate key presses/releases and to input text.
  • 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.

Type Aliases§