kbd-global
System-wide hotkeys on Linux for the kbd workspace.
kbd-global runs a background thread that reads from evdev input devices, feeds events through kbd's dispatcher, and fires your callbacks when bindings match. It handles device discovery, hotplug, and the event loop so you don't have to. Works on Wayland, X11, and TTY — no display server integration needed.
Requirements
kbd-global reads /dev/input/event* directly. Your user needs permission to access input devices:
Log out and back in for the group change to take effect.
Example
use ;
use Key;
use HotkeyManager;
let manager = new?;
// Registration returns a guard — the binding lives until the guard is dropped
let _guard = manager.register?;
// Keep the main thread alive so the background listener keeps running
park;
HotkeyManager is the main entry point. It spawns the engine thread on creation and communicates with it over a channel. Registration returns a BindingGuard — dropping it unregisters the binding. Dropping the manager (or calling shutdown()) stops the runtime.
Layers
Layers let you swap between different binding sets at runtime — think vim modes, or a "gaming" layer that disables desktop shortcuts:
use Action;
use Key;
use Layer;
use HotkeyManager;
let manager = new?;
let layer = new
.bind?
.bind?
.bind?;
let insert = new
.bind?;
manager.define_layer?;
manager.define_layer?;
manager.push_layer?;
Layers stack — the most recently pushed layer is checked first. PopLayer removes the top layer, ToggleLayer adds or removes by name.
Grab mode
With the grab feature enabled, kbd-global can exclusively capture input devices so matched keys never reach other applications. Unmatched events are forwarded through a virtual uinput device.
use HotkeyManager;
let manager = builder
.grab
.build?;
Grab mode requires write access to /dev/uinput in addition to read access on /dev/input/.
Feature flags
| Feature | Effect |
|---|---|
grab |
Exclusive device capture via EVIOCGRAB with uinput forwarding for unmatched events |
serde |
Serde support for shared kbd key and hotkey types |
Current status
- Linux only
- evdev is the only backend
Action::EmitHotkeyandAction::EmitSequenceare not yet implemented in the runtime
Related crates
kbd— the core matching engine, used directly for in-process shortcutskbd-evdev— the low-level device backend this crate wraps, for when you need to own the poll loop yourself- Bridge crates for framework integration:
kbd-crossterm,kbd-egui,kbd-iced,kbd-tao,kbd-winit
License
kbd-global is licensed under the MIT license. See the LICENSE file for more information.