pub enum KeyCode {
Show 27 variants
Backspace,
Enter,
Left,
Right,
Up,
Down,
Home,
End,
PageUp,
PageDown,
Tab,
BackTab,
Delete,
Insert,
F(u8),
Char(char),
Null,
Esc,
CapsLock,
ScrollLock,
NumLock,
PrintScreen,
Pause,
Menu,
KeypadBegin,
Media(MediaKeyCode),
Modifier(ModifierKeyCode),
}Expand description
Represents a key.
Variants§
Backspace
Backspace key (Delete on macOS, Backspace on other platforms).
Enter
Enter key.
Left
Left arrow key.
Right
Right arrow key.
Up
Up arrow key.
Down
Down arrow key.
Home
Home key.
End
End key.
PageUp
Page up key.
PageDown
Page down key.
Tab
Tab key.
BackTab
Shift + Tab key.
Delete
Delete key. (Fn+Delete on macOS, Delete on other platforms)
Insert
Insert key.
F(u8)
F key.
KeyCode::F(1) represents F1 key, etc.
Char(char)
A character.
KeyCode::Char('c') represents c character, etc.
Null
Null.
Esc
Escape key.
CapsLock
Caps Lock key.
Note: this key can only be read if
KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES has been enabled with
PushKeyboardEnhancementFlags.
ScrollLock
Scroll Lock key.
Note: this key can only be read if
KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES has been enabled with
PushKeyboardEnhancementFlags.
NumLock
Num Lock key.
Note: this key can only be read if
KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES has been enabled with
PushKeyboardEnhancementFlags.
PrintScreen
Print Screen key.
Note: this key can only be read if
KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES has been enabled with
PushKeyboardEnhancementFlags.
Pause
Pause key.
Note: this key can only be read if
KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES has been enabled with
PushKeyboardEnhancementFlags.
Menu
Menu key.
Note: this key can only be read if
KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES has been enabled with
PushKeyboardEnhancementFlags.
KeypadBegin
The “Begin” key (often mapped to the 5 key when Num Lock is turned on).
Note: this key can only be read if
KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES has been enabled with
PushKeyboardEnhancementFlags.
Media(MediaKeyCode)
A media key.
Note: these keys can only be read if
KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES has been enabled with
PushKeyboardEnhancementFlags.
Modifier(ModifierKeyCode)
A modifier key.
Note: these keys can only be read if both
KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES and
KeyboardEnhancementFlags::REPORT_ALL_KEYS_AS_ESCAPE_CODES have been enabled with
PushKeyboardEnhancementFlags.
Implementations§
Source§impl KeyCode
impl KeyCode
Sourcepub fn is_function_key(&self, n: u8) -> bool
pub fn is_function_key(&self, n: u8) -> bool
Returns true if the key code is the given function key.
§Examples
assert!(KeyCode::F(1).is_function_key(1));
assert!(!KeyCode::F(1).is_function_key(2));Sourcepub fn is_char(&self, c: char) -> bool
pub fn is_char(&self, c: char) -> bool
Returns true if the key code is the given character.
§Examples
assert!(KeyCode::Char('a').is_char('a'));
assert!(!KeyCode::Char('a').is_char('b'));
assert!(!KeyCode::F(1).is_char('a'));Sourcepub fn as_char(&self) -> Option<char>
pub fn as_char(&self) -> Option<char>
Returns the character if the key code is a character key.
Returns None if the key code is not a character key.
§Examples
assert_eq!(KeyCode::Char('a').as_char(), Some('a'));
assert_eq!(KeyCode::F(1).as_char(), None);Sourcepub fn is_media_key(&self, media: MediaKeyCode) -> bool
pub fn is_media_key(&self, media: MediaKeyCode) -> bool
Returns true if the key code is the given media key.
Note: this method requires
KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES to be enabled with
PushKeyboardEnhancementFlags.
§Examples
assert!(KeyCode::Media(MediaKeyCode::Play).is_media_key(MediaKeyCode::Play));
assert!(!KeyCode::Media(MediaKeyCode::Play).is_media_key(MediaKeyCode::Pause));Sourcepub fn is_modifier(&self, modifier: ModifierKeyCode) -> bool
pub fn is_modifier(&self, modifier: ModifierKeyCode) -> bool
Returns true if the key code is the given modifier key.
Note: this method requires both
KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES and
KeyboardEnhancementFlags::REPORT_ALL_KEYS_AS_ESCAPE_CODES to be enabled with
PushKeyboardEnhancementFlags.
§Examples
assert!(KeyCode::Modifier(ModifierKeyCode::LeftShift).is_modifier(ModifierKeyCode::LeftShift));
assert!(!KeyCode::Modifier(ModifierKeyCode::LeftShift).is_modifier(ModifierKeyCode::RightShift));Trait Implementations§
Source§impl Display for KeyCode
impl Display for KeyCode
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>
Formats the KeyCode using the given formatter.
§Platform-specific Notes
On macOS, the Backspace key is displayed as “Delete”, the Delete key is displayed as “Fwd Del”, and the Enter key is displayed as “Return”. See https://support.apple.com/guide/applestyleguide/welcome/1.0/web.
On other platforms, the Backspace key is displayed as “Backspace”, the Delete key is displayed as “Del”, and the Enter key is displayed as “Enter”.
Source§impl PartialOrd for KeyCode
impl PartialOrd for KeyCode
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 UnwindSafe for KeyCode
Blanket Implementations§
Source§impl<D> AsBuilderPart<D, D> for Dwhere
D: Display,
impl<D> AsBuilderPart<D, D> for Dwhere
D: Display,
Source§fn as_builder_part(&self) -> BuilderPart<'_, D, D>
fn as_builder_part(&self) -> BuilderPart<'_, D, D>
BuilderPart fro this valueSource§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,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
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§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.