pub enum KeyCode {
Show 41 variants
Char(char),
F(u8),
Left,
Right,
Up,
Down,
Home,
End,
PageUp,
PageDown,
Backspace,
Delete,
Enter,
Tab,
Escape,
Space,
Insert,
PrintScreen,
Pause,
Menu,
Clear,
Shift,
Ctrl,
Alt,
Super,
CapsLock,
NumLock,
ScrollLock,
MediaPlay,
MediaPause,
MediaPlayPause,
MediaStop,
MediaNext,
MediaPrev,
MediaRecord,
MediaFastForward,
MediaRewind,
VolumeUp,
VolumeDown,
VolumeMute,
Unknown,
}Expand description
A physical key press: the full keyboard, decoupled from any windowing
library. EditKey is the input widget’s closed navigation vocabulary;
this is what apps that own their own text model bind against — an editor
with modal keymaps, a game, a scripted panel.
Variants§
Char(char)
A character-producing key, as the active layout produced it — W
and $ arrive as themselves (shift already applied), which is what
keymaps bind against.
A layout that produces something outside ASCII does not reach here:
the driver substitutes the US-QWERTY key at that position, as Shift
prints it (J, :; unshifted under Alt), so a keymap written in
Latin keeps working on a Cyrillic, Greek, Hebrew or Arabic layout
instead of matching nothing at all. text is still the layout’s
own character. See KeyPress::from_layout, KeyPress::physical:
the layout still wins whenever it speaks ASCII.
F(u8)
Function key: F(1) .. F(35).
Left
Right
Up
Down
Home
End
PageUp
PageDown
Backspace
Delete
Enter
Tab
Escape
Space
Insert
PrintScreen
Print Screen / SysRq.
Pause
Pause / Break.
Menu
The context-menu key (the one beside the right-hand Ctrl).
Clear
The keypad’s middle key with Num Lock off (X11’s KP_Begin), and
Clear where a keyboard has one.
Shift
The modifier keys themselves, which side in KeyPress::location.
Heard only by a sink that asked for them
(crate::NodeSpec::modifier_keys): to every other sink a
modifier is only ever held, in KeyMods, and a Shift pressed
between two keys of a sequence must not read as a key between
them.
Ctrl
Alt
Super
Command on a Mac, the Windows key, Super.
CapsLock
The lock keys, as keys; what they lock is KeyPress::locks.
Modifier keys as far as delivery goes (see KeyCode::Shift).
NumLock
ScrollLock
MediaPlay
MediaPause
MediaPlayPause
MediaStop
MediaNext
MediaPrev
MediaRecord
MediaFastForward
MediaRewind
VolumeUp
VolumeDown
VolumeMute
Unknown
A key this vocabulary doesn’t name; KeyPress::text may still carry
what it would insert.
Implementations§
Source§impl KeyCode
impl KeyCode
Sourcepub fn name(self) -> String
pub fn name(self) -> String
Stable lowercase name for the data payload: "a", "f5", "pageup".
Bindings in C and Lua match on these.
Sourcepub fn named() -> &'static [(KeyCode, &'static str)]
pub fn named() -> &'static [(KeyCode, &'static str)]
Every key this vocabulary names but Char and F, with its
payload name — for a binding that lists them (the generated key
name types) and a test that walks them.
Sourcepub fn is_modifier(self) -> bool
pub fn is_modifier(self) -> bool
Whether this is a modifier or lock key — heard only by a sink
that asked for them (crate::NodeSpec::modifier_keys).
Sourcepub fn from_name(s: &str) -> Option<KeyCode>
pub fn from_name(s: &str) -> Option<KeyCode>
The inverse of KeyCode::name: the name a binding spells a key
with. A single character is that character (already
layout-resolved, so "W" and "$" arrive as themselves), "f1"
.. "f35" a function key, and the rest are the names above.
None for a name this vocabulary does not know — every binding
that takes keys as strings parses them here, so they cannot drift
apart.
Sourcepub fn typed(self, mods: KeyMods) -> Option<String>
pub fn typed(self, mods: KeyMods) -> Option<String>
What a press of this key types, for a door whose host did not say: the character itself, a space for Space, nothing for any other named key or under Ctrl, Alt or Super — the rule the winit runner reads off the layout’s own key.
Asked of the key as the layout named it, never of the code
KeyPress::from_layout resolved: on a Russian layout ⇧ on the
key printed ; binds as : and types Ж, and asking the stand-in
typed the : into an editor.
Trait Implementations§
impl Copy for KeyCode
impl Eq for KeyCode
impl StructuralPartialEq for KeyCode
Auto Trait Implementations§
impl Freeze for KeyCode
impl RefUnwindSafe for KeyCode
impl Send for KeyCode
impl Sync for KeyCode
impl Unpin for KeyCode
impl UnsafeUnpin for KeyCode
impl UnwindSafe for KeyCode
Blanket Implementations§
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.