kbd-evdev
Linux evdev backend for kbd — device discovery, hotplug, grab, and event forwarding.
Features
- Device discovery — scans
/dev/input/for keyboards (devices supporting A–Z + Enter) - Hotplug — inotify watch for device add/remove at runtime
- Exclusive grab —
EVIOCGRABfor intercepting events before other applications - Event forwarding — uinput virtual device re-emits unmatched events in grab mode
- Key conversion — extension traits for
evdev::KeyCode↔kbd::Key
Prerequisites
-
Linux only — uses
/dev/input/,inotify, and/dev/uinput -
Read access to
/dev/input/— run as root or add your user to theinputgroup:# log out and back in for the group change to take effect -
Write access to
/dev/uinput(grab mode only) — needed for the virtual device that forwards unmatched events
Usage
[]
= "0.1"
Key conversion
use KeyCode;
use *;
use ;
// evdev → kbd
let key: Key = KEY_A.to_key;
assert_eq!;
// kbd → evdev
let code: KeyCode = A.to_key_code;
assert_eq!;
Device polling
use Path;
use ;
let mut manager = new;
// Build pollfd array from manager's file descriptors
let mut pollfds: = manager
.poll_fds
.iter
.map
.collect;
// Poll and process events
unsafe ;
let result = manager.process_polled_events;
for event in &result.key_events
Architecture
/dev/input/event* DeviceManager
├─ event0 ──┐ ┌─ discover + poll ──→ DeviceKeyEvent
├─ event1 ──┼──────→│ hotplug (inotify) │
└─ event2 ──┘ └───────────────────────┘
│
EvdevKeyCodeExt::to_key()
│
▼
kbd::Key
See also
kbd— core key types, matching, and layerskbd-global— threaded runtime built on this crate
License
kbd-evdev is licensed under the MIT license. See the LICENSE file for more information.