pub enum KeyCode {
Show 47 variants
Char(char),
F(u8),
Find,
Select,
Up,
Down,
Left,
Right,
Home,
End,
Begin,
PageUp,
PageDown,
Backspace,
Delete,
Insert,
Tab,
Enter,
Space,
Escape,
CapsLock,
ScrollLock,
NumLock,
PrintScreen,
Pause,
Menu,
MediaPlay,
MediaPause,
MediaPlayPause,
MediaReverse,
MediaStop,
MediaRewind,
MediaFastForward,
MediaNext,
MediaPrev,
MediaRecord,
VolumeUp,
VolumeDown,
VolumeMute,
Shift,
Ctrl,
Alt,
Super,
Hyper,
Meta,
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, media keys, and 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.
Begin
Begin 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.
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.
Shift
Shift key.
Ctrl
Control key.
Alt
Alt key.
Super
Super key.
Hyper
Hyper key.
Meta
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> ErasedDestructor for Twhere
T: 'static,
§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