pub enum KeyCode {
Show 81 variants
Char(char),
F(u8),
Find,
Select,
Up,
Down,
Left,
Right,
Home,
End,
PageUp,
PageDown,
Backspace,
Delete,
Insert,
Tab,
Enter,
Space,
Escape,
CapsLock,
ScrollLock,
NumLock,
PrintScreen,
Pause,
Menu,
KpEnter,
KpAdd,
KpSubtract,
KpMultiply,
KpDivide,
KpDecimal,
KpEqual,
KpSeparator,
KpLeft,
KpRight,
KpUp,
KpDown,
KpPageUp,
KpPageDown,
KpHome,
KpEnd,
KpInsert,
KpDelete,
KpBegin,
Kp0,
Kp1,
Kp2,
Kp3,
Kp4,
Kp5,
Kp6,
Kp7,
Kp8,
Kp9,
MediaPlay,
MediaPause,
MediaPlayPause,
MediaReverse,
MediaStop,
MediaRewind,
MediaFastForward,
MediaNext,
MediaPrev,
MediaRecord,
VolumeUp,
VolumeDown,
VolumeMute,
LeftShift,
RightShift,
LeftCtrl,
RightCtrl,
LeftAlt,
RightAlt,
LeftSuper,
RightSuper,
LeftHyper,
RightHyper,
LeftMeta,
RightMeta,
IsoLevel3Shift,
IsoLevel5Shift,
}Expand description
Logical identity of a key, before modifiers are considered.
KeyCode is intentionally broader than printable text: it covers named
navigation/editing keys, keypad keys, media keys, and the richer modifier-key
identities reported by modern keyboard protocols. Combine it with
KeyModifiers in a Key to represent a full key event.
Use KeyCode::function when constructing function keys from untrusted
numeric input; the raw KeyCode::F variant is public for pattern matching
and decoder construction.
Variants§
Char(char)
A Unicode character key.
Printable spaces are normally represented as KeyCode::Space for
cross-decoder stability. Other printable and non-control Unicode scalar
values use this variant after Key::normalize applies case folding.
F(u8)
Function key. Valid range is 1..=35 (xterm goes to F20,
kitty extends to F35). Construct via KeyCode::function for
a checked builder; the bare variant is pub so decoders can
emit literals, but downstream code matching on F(n) should
treat values outside the valid range as bugs.
Find
Legacy VT220 Find key, distinct from Home. Only emitted when the decoder is configured to recognize the legacy Find key.
Select
Legacy VT220 Select key, distinct from End. Only emitted when the decoder is configured to recognize the legacy Select key.
Up
Up arrow key.
Down
Down arrow key.
Left
Left arrow key.
Right
Right arrow key.
Home
Home key.
End
End key.
PageUp
Page Up key.
PageDown
Page Down key.
Backspace
Backspace key.
Delete
Delete key.
Insert
Insert key.
Tab
Tab key.
Enter
Enter key.
Space
Space key.
The space bar decodes to this variant, not KeyCode::Char(' ')
— match on KeyCode::Space (a Char(' ') arm never fires). It still
reports text of " ", so text entry via Key::text is unaffected.
Rust has no variant aliases; to treat both alike by character, use
Key::char, which returns Some(' ') for Space and Char(' ').
Escape
Escape key.
CapsLock
Caps Lock key.
ScrollLock
Scroll Lock key.
NumLock
Num Lock key.
PrintScreen
Print Screen key.
Pause
Pause key.
Menu
Menu key.
KpEnter
Keypad Enter key.
KpAdd
Keypad Add key.
KpSubtract
Keypad Subtract key.
KpMultiply
Keypad Multiply key.
KpDivide
Keypad Divide key.
KpDecimal
Keypad Decimal key.
KpEqual
Keypad Equal key.
KpSeparator
Keypad Separator key.
KpLeft
Keypad Left key.
KpRight
Keypad Right key.
KpUp
Keypad Up key.
KpDown
Keypad Down key.
KpPageUp
Keypad Page Up key.
KpPageDown
Keypad Page Down key.
KpHome
Keypad Home key.
KpEnd
Keypad End key.
KpInsert
Keypad Insert key.
KpDelete
Keypad Delete key.
KpBegin
Keypad Begin key.
Kp0
Keypad 0 key.
Kp1
Keypad 1 key.
Kp2
Keypad 2 key.
Kp3
Keypad 3 key.
Kp4
Keypad 4 key.
Kp5
Keypad 5 key.
Kp6
Keypad 6 key.
Kp7
Keypad 7 key.
Kp8
Keypad 8 key.
Kp9
Keypad 9 key.
MediaPlay
Media Play key.
MediaPause
Media Pause key.
MediaPlayPause
Media Play/Pause key.
MediaReverse
Media Reverse key.
MediaStop
Media Stop key.
MediaRewind
Media Rewind key.
MediaFastForward
Media Fast Forward key.
MediaNext
Media Next key.
MediaPrev
Media Previous key.
MediaRecord
Media Record key.
VolumeUp
Volume Up key.
VolumeDown
Volume Down key.
VolumeMute
Volume Mute key.
LeftShift
Left Shift key.
RightShift
Right Shift key.
LeftCtrl
Left Control key.
RightCtrl
Right Control key.
LeftAlt
Left Alt key.
RightAlt
Right Alt key.
LeftSuper
Left Super key.
RightSuper
Right Super key.
LeftHyper
Left Hyper key.
RightHyper
Right Hyper key.
LeftMeta
Left Meta key.
RightMeta
Right Meta key.
IsoLevel3Shift
ISO Level 3 Shift (typically AltGr).
IsoLevel5Shift
ISO Level 5 Shift.
Implementations§
Source§impl KeyCode
impl KeyCode
Sourcepub const FUNCTION_KEY_MAX: u8 = 35
pub const FUNCTION_KEY_MAX: u8 = 35
Highest valid function-key index accepted by KeyCode::function.
Function keys are represented as F(1) through F(35). Values outside
that range are not produced by the checked constructor.
Sourcepub fn function(n: u8) -> Option<KeyCode>
pub fn function(n: u8) -> Option<KeyCode>
Construct a checked function-key code.
Returns Some(KeyCode::F(n)) when n is in
1..=KeyCode::FUNCTION_KEY_MAX; returns None for 0 or values above
the supported range. This function is useful when decoding or accepting
user input that may contain an invalid function-key number. It never
panics.
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string()] Read more§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString]. Read more