Skip to main content

Crate kbd_iced

Crate kbd_iced 

Source
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

§Key mapping

icedkbdNotes
Code::KeyACode::KeyZKey::AKey::ZLetters
Code::Digit0Code::Digit9Key::DIGIT0Key::DIGIT9Digits
Code::F1Code::F35Key::F1Key::F35Function keys
Code::Numpad0Code::Numpad9Key::NUMPAD0Key::NUMPAD9Numpad
Code::Enter, Code::Escape, …Key::ENTER, Key::ESCAPE, …Navigation / editing
Code::ControlLeft, …Key::CONTROL_LEFT, …Modifier keys as triggers
Code::SuperLeft / Code::MetaKey::META_LEFTiced’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(_)NoneNo mapping possible

§Modifier mapping

§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§

IcedEventExt
Convert an iced keyboard Event to a kbd Hotkey.
IcedKeyExt
Convert an iced physical key type to a kbd Key.
IcedModifiersExt
Convert iced Modifiers bitflags to a sorted Vec<Modifier>.