Skip to main content

Crate kbd

Crate kbd 

Source
Expand description

Pure-logic hotkey engine.

kbd provides the domain types and matching logic that every hotkey system needs: key types, modifier tracking, binding matching, layer stacks, and sequence resolution. It has zero platform dependencies and can be embedded in any event loop — winit, GPUI, Smithay, a game loop, or a compositor.

§Quick Start

Register a hotkey, feed key events, and check for matches:

use kbd::prelude::*;

let mut dispatcher = Dispatcher::new();

// Register Ctrl+S as a global binding
let id = dispatcher.register(
    Hotkey::new(Key::S).modifier(Modifier::Ctrl),
    Action::Suppress,
).unwrap();

// Simulate a key press
let result = dispatcher.process(
    &Hotkey::new(Key::S).modifier(Modifier::Ctrl),
    KeyTransition::Press,
);
assert!(matches!(result, MatchResult::Matched { .. }));

§Feature Flags

FlagDefaultEffect
serdeoffAdds Serialize/Deserialize to key and hotkey types

§See Also

Modules§

action
The Action enum — what happens when a binding matches.
binding
The unified binding types — pattern + action + options.
dispatcher
Binding dispatcher — finds which binding (if any) matches a key event.
error
Error types for hotkey operations.
hotkey
Hotkey composition types: Modifier, Hotkey, HotkeySequence.
introspection
Introspection types — snapshots of dispatcher state for UI and debugging.
key
Physical key type: Key.
key_state
Key state tracking — single source of truth for what’s pressed.
layer
Layers — named, stackable collections of bindings.
prelude
Convenience re-exports for common types.