Skip to main content

Crate kbd_evdev

Crate kbd_evdev 

Source
Expand description

Linux evdev backend for kbd.

This crate provides the low-level Linux input layer that kbd-global builds on. It handles:

  • Device discovery — scan /dev/input/ for keyboards (devices supporting A–Z + Enter)
  • Hotplug — inotify watch for device add/remove at runtime
  • Exclusive grabEVIOCGRAB for intercepting events before other applications see them
  • Event forwardingUinputForwarder re-emits unmatched events through a virtual device so they still reach applications in grab mode
  • Key conversion — extension traits (EvdevKeyCodeExt, KbdKeyExt) for converting between evdev::KeyCode and kbd::key::Key

§Prerequisites

  • Linux only — this crate uses /dev/input/, inotify, and /dev/uinput.

  • Read access to /dev/input/ — either run as root, or add your user to the input group:

    sudo usermod -aG input $USER
    # log out and back in for the group change to take effect
  • Write access to /dev/uinput (only for grab mode) — needed to create the virtual device that forwards unmatched events.

§Architecture

/dev/input/event*          DeviceManager
  ├─ event0  ──┐       ┌─ discover + poll ──→ DeviceKeyEvent
  ├─ event1  ──┼──────→│  hotplug (inotify)   │
  └─ event2  ──┘       └───────────────────────┘
                                               │
                                     EvdevKeyCodeExt::to_key()
                                               │
                                               ▼
                                          kbd::Key
                                               │
                             ┌─────────────────┼─────────────────┐
                             │                 │                 │
                          Dispatcher          KeyState     UinputForwarder
                       (kbd core)        (kbd core)     (grab mode only)

§Usage

Most users should use kbd-global which wraps this crate in a threaded runtime. Use kbd-evdev directly when you need low-level control over the poll loop.

§See also

  • kbd — core key types, matching, and layers
  • kbd-global — threaded runtime built on this crate

Re-exports§

pub use crate::convert::EvdevKeyCodeExt;
pub use crate::convert::KbdKeyExt;

Modules§

convert
Extension traits for converting between evdev::KeyCode and kbd::key::Key. Extension traits for converting between evdev key codes and kbd key types.
devices
Device discovery, hotplug monitoring, and event polling. Device discovery, hotplug, and capability detection.
error
Error types for the evdev backend. Error types for the evdev backend.
forwarder
Virtual uinput device for forwarding and emitting key events. uinput virtual device for event forwarding and emission.