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.
pub fn shift(&self) -> bool
pub fn primary(&self) -> bool
pub fn alt(&self) -> bool
Trait Implementations§
impl StructuralPartialEq for KeyEvent
Auto Trait Implementations§
impl Freeze for KeyEvent
impl RefUnwindSafe for KeyEvent
impl Send for KeyEvent
impl Sync for KeyEvent
impl Unpin for KeyEvent
impl UnsafeUnpin for KeyEvent
impl UnwindSafe for KeyEvent
Blanket Implementations§
§impl<T> AnyEq for T
impl<T> AnyEq for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more