Skip to main content

KeyCode

Enum KeyCode 

Source
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

Source

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.

Source

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§

Source§

impl Clone for KeyCode

Source§

fn clone(&self) -> KeyCode

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for KeyCode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for KeyCode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl FromStr for KeyCode

Source§

type Err = ParseKeyError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for KeyCode

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for KeyCode

Source§

fn eq(&self, other: &KeyCode) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for KeyCode

Source§

impl Eq for KeyCode

Source§

impl StructuralPartialEq for KeyCode

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> ToCompactString for T
where T: Display,

§

fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>

Fallible version of [ToCompactString::to_compact_string()] Read more
§

fn to_compact_string(&self) -> CompactString

Converts the given value to a [CompactString]. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> ErasedDestructor for T
where T: 'static,