Crate evdev_shortcut

Source
Expand description

Global keyboard shortcuts using evdev.

By connecting to the input devices directly with evdev the shortcuts can work regardless of the environment, they will work under X11, wayland and in the terminal.

This does come at the cost of having to run the program with elevated permissions. See shortcutd for a solution to running the elevated input handling in a separate process.

Example:

let listener = ShortcutListener::new();
listener.add(Shortcut::new(&[Modifier::Meta], Key::KeyN));

let devices =
    glob::glob("/dev/input/by-id/*-kbd")?.collect::<Result<Vec<PathBuf>, GlobError>>()?;

let stream = listener.listen(&devices)?;
pin!(stream);

while let Some(event) = stream.next().await {
    println!("{} {}", event.shortcut, event.state);
}

Structs§

DeviceOpenError
Error emitted when an input device can’t be opened
ModifierList
Set of modifier keys for shortcuts
Shortcut
A keyboard shortcut consisting of zero or more modifier keys and a non-modifier key
ShortcutEvent
Event emitted when a shortcut is pressed or released.
ShortcutListener
A listener for shortcut events

Enums§

Key
evdev keycode
Modifier
Modifier key for shortcuts
ShortcutState
Whether the shortcut was pressed or released