kbd-evdev 0.2.0

evdev backend for kbd — Linux input device discovery, hotplug, grab, and event forwarding.
Documentation

kbd-evdev

crates.io docs.rs

Low-level Linux input backend for the kbd workspace.

Most applications should start with kbd-global, which wraps this crate in a threaded runtime. Use kbd-evdev directly when you need to own the poll loop yourself — your own event loop, your own threading, your own timing.

Requirements

  • Linux only
  • Read access to /dev/input/
  • Write access to /dev/uinput if you use grab mode and forwarding

To read input devices without running as root, add your user to the input group:

sudo usermod -aG input $USER

Log out and back in for the group change to take effect.

What it handles

  • Device discovery — scans /dev/input/ for keyboards (devices that support A–Z + Enter)
  • Hotplug — inotify watch picks up devices added or removed at runtime
  • Exclusive grabEVIOCGRAB intercepts events before other applications see them
  • Event forwarding — a uinput virtual device re-emits unmatched events in grab mode so other apps still work
  • Key conversion — extension traits for evdev::KeyCodekbd::key::Key

Example

Convert between evdev and kbd key types:

use evdev::KeyCode;
use kbd::key::Key;
use kbd_evdev::convert::{EvdevKeyCodeExt, KbdKeyExt};

let key: Key = KeyCode::KEY_A.to_key();
assert_eq!(key, Key::A);

let code: KeyCode = Key::A.to_key_code();
assert_eq!(code, KeyCode::KEY_A);

Discover and poll devices:

use std::path::Path;
use kbd_evdev::devices::{DeviceGrabMode, DeviceManager};

let manager = DeviceManager::new(Path::new("/dev/input"), DeviceGrabMode::Shared);
let _poll_fds = manager.poll_fds();

Call poll(2) on DeviceManager::poll_fds(), then pass the ready descriptors to DeviceManager::process_polled_events() — you get back key events (with device identity and press/release state) and disconnection notifications.

Related crates

  • kbd — the core matching engine that processes the key events this crate produces
  • kbd-global — threaded runtime built on top of this crate, handles the event loop for you

License

kbd-evdev is licensed under the MIT license. See the LICENSE file for more information.