Expand description
Egui key event conversions for kbd.
This crate converts egui’s key events into kbd’s unified types so
that GUI key events (from egui) and global hotkey events (from
kbd-global) can feed into the same
Dispatcher. This is useful in egui
apps that want both in-window shortcuts and system-wide hotkeys
handled through a single hotkey registry.
Egui has a smaller, custom key enum that is not 1:1 with the W3C
specification — some physical keys have no egui equivalent, some egui
keys are logical/shifted characters without a single physical key
equivalent (e.g., Colon, Pipe, Plus), and egui combines some
concepts differently.
§Extension traits
EguiKeyExt— converts anegui::Keyto akbd::key::Key.EguiModifiersExt— convertsegui::Modifiersto aVec<Modifier>.EguiEventExt— converts a fullegui::Eventkeyboard event to akbd::hotkey::Hotkey.
§Key mapping
| egui | kbd | Notes |
|---|---|---|
Key::A – Key::Z | Key::A – Key::Z | Letters |
Key::Num0 – Key::Num9 | Key::DIGIT0 – Key::DIGIT9 | Digits |
Key::F1 – Key::F35 | Key::F1 – Key::F35 | Function keys |
Key::Minus, Key::Period, … | Key::MINUS, Key::PERIOD, … | Physical-position punctuation |
Key::ArrowDown, Key::Enter, … | Key::ARROW_DOWN, Key::ENTER, … | Navigation / editing |
Key::Copy, Key::Cut, Key::Paste | Key::COPY, Key::CUT, Key::PASTE | Clipboard |
Key::Colon, Key::Pipe, Key::Plus, … | None | Logical/shifted — no single physical key |
§Modifier mapping
| egui | kbd | Notes |
|---|---|---|
ctrl | Modifier::Ctrl | |
shift | Modifier::Shift | |
alt | Modifier::Alt | |
mac_cmd | Modifier::Super | Avoids double-counting with command on macOS |
§Usage
use egui::{Key as EguiKey, Modifiers};
use kbd::prelude::*;
use kbd_egui::{EguiEventExt, EguiKeyExt, EguiModifiersExt};
// Single key conversion
let key = EguiKey::A.to_key();
assert_eq!(key, Some(Key::A));
// Modifier conversion
let mods = Modifiers::CTRL.to_modifiers();
assert_eq!(mods, vec![Modifier::Ctrl]);
// Full event conversion
let event = egui::Event::Key {
key: EguiKey::C,
physical_key: None,
pressed: true,
repeat: false,
modifiers: Modifiers::CTRL,
};
let hotkey = event.to_hotkey();
assert_eq!(hotkey, Some(Hotkey::new(Key::C).modifier(Modifier::Ctrl)));Traits§
- Egui
Event Ext - Convert an
egui::Eventkeyboard event to akbdHotkey. - Egui
KeyExt - Convert an
egui::Keyto akbdKey. - Egui
Modifiers Ext - Convert
egui::Modifiersto a sortedVec<Modifier>.