Trait enigo::Keyboard

source ·
pub trait Keyboard {
    // Required methods
    fn key(&mut self, key: Key, direction: Direction) -> InputResult<()>;
    fn raw(&mut self, keycode: u16, direction: Direction) -> InputResult<()>;

    // Provided method
    fn text(&mut self, text: &str) -> InputResult<()> { ... }
}
Expand description

Contains functions to simulate key presses/releases and to input text.

For entering text, the Keyboard::text function is best. If you want to enter a key without having to worry about the layout or the keymap, use the Keyboard::key function. If you want a specific (physical) key to be pressed (e.g WASD for games), use the Keyboard::raw function. The resulting keysym will depend on the layout/keymap.

Required Methods§

source

fn key(&mut self, key: Key, direction: Direction) -> InputResult<()>

Sends an individual key event. It will enter the keysym (virtual key). Have a look at the Keyboard::raw function, if you want to enter a keycode.

Some of the keys are specific to a platform.

§Errors

Have a look at the documentation of InputError to see under which conditions an error will be returned.

source

fn raw(&mut self, keycode: u16, direction: Direction) -> InputResult<()>

Sends a raw keycode. The keycode may or may not be mapped on the current layout. You have to make sure of that yourself. This can be useful if you want to simulate a press regardless of the layout (WASD on video games). Have a look at the Keyboard::key function, if you just want to enter a specific key and don’t want to worry about the layout/keymap. Windows only: If you want to enter the keycode (scancode) of an extended key, you need to set extra bits. You can for example do: enigo.raw(45 | EXT, Direction::Click)

§Errors

Have a look at the documentation of InputError to see under which conditions an error will be returned.

Provided Methods§

source

fn text(&mut self, text: &str) -> InputResult<()>

Enter the text Use a fast method to enter the text, if it is available. You can use unicode here like: ❤️. This works regardless of the current keyboard layout. You cannot use this function for entering shortcuts or something similar. For shortcuts, use the Keyboard::key method instead.

§Errors

The text should not contain any NULL bytes (\0). Have a look at the documentation of InputError to see under which other conditions an error will be returned.

Implementors§