evdev-shortcut

Crates.ioevdev-shortcut
lib.rsevdev-shortcut
version0.1.5
created_at2023-06-17 14:05:58.075298+00
updated_at2025-06-09 15:32:48.310392+00
descriptionGlobal shortcuts using evdev
homepage
repositoryhttps://codeberg.org/icewind/evdev-shortcut
max_upload_size
id892917
size56,844
Robin Appelman (icewind1991)

documentation

README

evdev-shortcut

Global shortcuts using evdev

Why

Because evdev exists at a level above the display server, evdev shortcuts will work with both X11, wayland, or headless/cli systems.

Usage

use std::path::PathBuf;
use glob::GlobError;
use evdev_shortcut::{ShortcutListener, Shortcut, Modifier, Key};
use tokio::pin;
use futures::stream::StreamExt;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    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);
    }
    Ok(())
}

Note that raw access to evdev devices is a privileged operation and usually requires running with elevated privileges. See shortcutd for a solution to running the elevated input handling in a separate process.

Commit count: 0

cargo fmt