Expand description
Global hotkey runtime for kbd.
Threaded engine, device management, and backend selection for Linux. The library handles platform complexity — evdev, portal, permissions, hotplug, virtual devices — so callers describe what patterns they care about and what should happen.
§Quick start
use kbd::prelude::*;
use kbd_global::HotkeyManager;
let manager = HotkeyManager::new()?;
let _guard = manager.register(
Hotkey::new(Key::C).modifier(Modifier::Ctrl).modifier(Modifier::Shift),
|| println!("fired"),
)?;§Concepts
Four concepts cover the library’s surface:
- Keys — physical keys on a keyboard (
Key,Modifier,Hotkey) - Bindings — “when this pattern matches, do that” (
Action,BindingOptions) - Layers — named groups of bindings, stackable (
Layer,LayerOptions) - Grab mode — exclusive device capture for interception and remapping
§Architecture
HotkeyManager is the public API. Internally it sends commands to a
dedicated engine thread over an mpsc channel, with an eventfd wake
mechanism to interrupt poll(). All mutable state lives in the engine —
no locks, no shared mutation.
┌──────────────────┐ Command ┌──────────────────┐
│ HotkeyManager │ ─────────────► │ Engine thread │
│ (command sender) │ ◄───────────── │ (event loop) │
└──────────────────┘ Reply └──────────────────┘
│
poll(devices + wake_fd)§Lifecycle
- Create a manager with
HotkeyManager::new()orHotkeyManager::builder() - Register hotkeys with
HotkeyManager::register()— returns aBindingGuard - Optionally define and push
Layers for context-dependent bindings - The engine thread processes key events and fires callbacks
- Drop the
BindingGuardto unregister, or callBindingGuard::unregister() - Drop the manager (or call
HotkeyManager::shutdown()) to stop
§Backend selection
Currently only Backend::Evdev is available — it reads /dev/input/event*
directly and works on Wayland, X11, and TTY. Your user must be in the
input group:
sudo usermod -aG input $USERUse the builder for explicit backend selection:
use kbd_global::{Backend, HotkeyManager};
let manager = HotkeyManager::builder()
.backend(Backend::Evdev)
.build()?;§Feature flags
| Feature | Effect |
|---|---|
grab | Enables exclusive device capture via EVIOCGRAB with uinput forwarding for non-hotkey events |
serde | Adds Serialize/Deserialize to key and hotkey types (via kbd) |
§See also
kbd— core dispatch engine, key types, and layer logic
Structs§
- Binding
Guard - RAII guard that keeps a binding alive until dropped. Keeps a registered binding alive.
- Hotkey
Manager - The main entry point — manages the engine thread and hotkey registration. Public manager API.
- Hotkey
Manager Builder - Builder for configuring backend and runtime options before starting. Builder for explicit backend and runtime options.