Global shortcuts using evdev
  • Rust 98.8%
  • Nix 1.2%
Find a file
2023-06-18 13:17:06 +02:00
.github/workflows update to streams 2023-06-17 15:52:26 +02:00
examples docs 2023-06-18 13:17:06 +02:00
src docs 2023-06-18 13:17:06 +02:00
.envrc update to streams 2023-06-17 15:52:26 +02:00
.gitignore update to streams 2023-06-17 15:52:26 +02:00
Cargo.lock bare shortcuts 2023-06-17 20:40:03 +02:00
Cargo.toml docs 2023-06-18 13:17:06 +02:00
flake.lock update to streams 2023-06-17 15:52:26 +02:00
flake.nix update to streams 2023-06-17 15:52:26 +02:00
README.md docs 2023-06-18 13:17:06 +02:00

evdev-shortcut

Global shortcuts using evdev

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.