pub struct KeyEvent {
pub key: String,
pub modifiers: u8,
}Fields§
§key: StringThe key’s name, in the web KeyboardEvent.key vocabulary every platform can map onto:
the four arrows (“ArrowLeft”, “ArrowRight”, “ArrowUp”, “ArrowDown”) and the ten digits
(“0” through “9”, from the main row or the numeric keypad) everywhere, plus
“Delete” and “Backspace” on backends with no menu bar (Cap::AppMenu unsupported),
where no accelerator can own those keys. A focused piece claims every key the route
carries, so offering them on a menu-bar platform would let a canvas swallow the Delete
its own Edit menu was about to act on (docs/menus.md). The two delete keys keep the
names the platform gives the physical keys (a Mac’s ⌫ is “Backspace” and its ⌦ is
“Delete”), so a handler that means “remove this” takes both. A digit arrives only while
neither KeyEvent::PRIMARY nor KeyEvent::ALT (nor a Mac’s Control) is held: ⌘1
and Ctrl+1 are accelerators, and a canvas claiming them would starve the menu. Most
backends name the digit the keypress types, so a layout whose number row needs Shift for
digits reports “1” with KeyEvent::SHIFT set; XAML and ArkUI read the physical key.
Backends emit Event::Key only while no text widget has focus; a field’s own editing
keys never surface here.
modifiers: u8Implementations§
Source§impl KeyEvent
impl KeyEvent
pub const SHIFT: u8 = 1
Sourcepub const PRIMARY: u8 = 2
pub const PRIMARY: u8 = 2
The platform’s command key: ⌘ on Apple platforms, Ctrl elsewhere (the
Shortcut::primary convention).
pub const ALT: u8 = 4
Sourcepub fn digit_name(c: char) -> Option<&'static str>
pub fn digit_name(c: char) -> Option<&'static str>
The key name for a typed character when it is one of the ten digits: what a backend
reports for a keypress that types 0–9.