Expand description
Iced key event conversions for kbd.
This crate converts iced’s keyboard events into kbd’s unified types
so that GUI key events (from iced) and global hotkey events (from
kbd-global) can feed into the same
Dispatcher. This is useful in iced
apps that want both in-window shortcuts and system-wide hotkeys
handled through a single hotkey registry.
iced defines its own W3C-derived key types: key::Code for physical
key positions and key::Physical wrapping Code with an unidentified
fallback. iced also has a logical key type for character/named key
identity, but this crate only converts physical keys — they are
layout-independent and match kbd’s model.
§Extension traits
IcedKeyExt— converts an icedkey::Codeorkey::Physicalto akbd::key::Key.IcedModifiersExt— converts icedModifiersto aVec<Modifier>.IcedEventExt— converts an iced keyboardEventto akbd::hotkey::Hotkey.
§Key mapping
| iced | kbd | Notes |
|---|---|---|
Code::KeyA – Code::KeyZ | Key::A – Key::Z | Letters |
Code::Digit0 – Code::Digit9 | Key::DIGIT0 – Key::DIGIT9 | Digits |
Code::F1 – Code::F35 | Key::F1 – Key::F35 | Function keys |
Code::Numpad0 – Code::Numpad9 | Key::NUMPAD0 – Key::NUMPAD9 | Numpad |
Code::Enter, Code::Escape, … | Key::ENTER, Key::ESCAPE, … | Navigation / editing |
Code::ControlLeft, … | Key::CONTROL_LEFT, … | Modifier keys as triggers |
Code::SuperLeft / Code::Meta | Key::META_LEFT | iced’s Super = kbd’s Meta |
Code::MediaPlayPause, … | Key::MEDIA_PLAY_PAUSE, … | Media keys |
Code::BrowserBack, … | Key::BROWSER_BACK, … | Browser keys |
Code::Convert, Code::Lang1, … | Key::CONVERT, Key::LANG1, … | CJK / international |
Physical::Unidentified(_) | None | No mapping possible |
§Modifier mapping
| iced | kbd |
|---|---|
CTRL | Modifier::Ctrl |
SHIFT | Modifier::Shift |
ALT | Modifier::Alt |
LOGO | Modifier::Super |
§Usage
use iced_core::keyboard::{key::Code, Modifiers};
use kbd::prelude::*;
use kbd_iced::{IcedKeyExt, IcedModifiersExt};
// Code conversion
let key = Code::KeyA.to_key();
assert_eq!(key, Some(Key::A));
// Modifier conversion
let mods = Modifiers::CTRL.to_modifiers();
assert_eq!(mods, vec![Modifier::Ctrl]);Traits§
- Iced
Event Ext - Convert an iced keyboard
Eventto akbdHotkey. - Iced
KeyExt - Convert an iced physical key type to a
kbdKey. - Iced
Modifiers Ext - Convert iced
Modifiersbitflags to a sortedVec<Modifier>.