Skip to main content

Crate kbd_egui

Crate kbd_egui 

Source
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

§Key mapping

eguikbdNotes
Key::AKey::ZKey::AKey::ZLetters
Key::Num0Key::Num9Key::DIGIT0Key::DIGIT9Digits
Key::F1Key::F35Key::F1Key::F35Function 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::PasteKey::COPY, Key::CUT, Key::PASTEClipboard
Key::Colon, Key::Pipe, Key::Plus, …NoneLogical/shifted — no single physical key

§Modifier mapping

eguikbdNotes
ctrlModifier::Ctrl
shiftModifier::Shift
altModifier::Alt
mac_cmdModifier::SuperAvoids 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§

EguiEventExt
Convert an egui::Event keyboard event to a kbd Hotkey.
EguiKeyExt
Convert an egui::Key to a kbd Key.
EguiModifiersExt
Convert egui::Modifiers to a sorted Vec<Modifier>.