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 const fn is_backspace(&self) -> bool
pub const fn is_backspace(&self) -> bool
Returns true
if this value is of type Backspace
. Returns false
otherwise
Sourcepub const fn is_enter(&self) -> bool
pub const fn is_enter(&self) -> bool
Returns true
if this value is of type Enter
. Returns false
otherwise
Sourcepub const fn is_left(&self) -> bool
pub const fn is_left(&self) -> bool
Returns true
if this value is of type Left
. Returns false
otherwise
Sourcepub const fn is_right(&self) -> bool
pub const fn is_right(&self) -> bool
Returns true
if this value is of type Right
. Returns false
otherwise
Sourcepub const fn is_up(&self) -> bool
pub const fn is_up(&self) -> bool
Returns true
if this value is of type Up
. Returns false
otherwise
Sourcepub const fn is_down(&self) -> bool
pub const fn is_down(&self) -> bool
Returns true
if this value is of type Down
. Returns false
otherwise
Sourcepub const fn is_home(&self) -> bool
pub const fn is_home(&self) -> bool
Returns true
if this value is of type Home
. Returns false
otherwise
Sourcepub const fn is_end(&self) -> bool
pub const fn is_end(&self) -> bool
Returns true
if this value is of type End
. Returns false
otherwise
Sourcepub const fn is_page_up(&self) -> bool
pub const fn is_page_up(&self) -> bool
Returns true
if this value is of type PageUp
. Returns false
otherwise
Sourcepub const fn is_page_down(&self) -> bool
pub const fn is_page_down(&self) -> bool
Returns true
if this value is of type PageDown
. Returns false
otherwise
Sourcepub const fn is_tab(&self) -> bool
pub const fn is_tab(&self) -> bool
Returns true
if this value is of type Tab
. Returns false
otherwise
Sourcepub const fn is_back_tab(&self) -> bool
pub const fn is_back_tab(&self) -> bool
Returns true
if this value is of type BackTab
. Returns false
otherwise
Sourcepub const fn is_delete(&self) -> bool
pub const fn is_delete(&self) -> bool
Returns true
if this value is of type Delete
. Returns false
otherwise
Sourcepub const fn is_insert(&self) -> bool
pub const fn is_insert(&self) -> bool
Returns true
if this value is of type Insert
. Returns false
otherwise
Sourcepub const fn is_null(&self) -> bool
pub const fn is_null(&self) -> bool
Returns true
if this value is of type Null
. Returns false
otherwise
Sourcepub const fn is_esc(&self) -> bool
pub const fn is_esc(&self) -> bool
Returns true
if this value is of type Esc
. Returns false
otherwise
Sourcepub const fn is_caps_lock(&self) -> bool
pub const fn is_caps_lock(&self) -> bool
Returns true
if this value is of type CapsLock
. Returns false
otherwise
Sourcepub const fn is_scroll_lock(&self) -> bool
pub const fn is_scroll_lock(&self) -> bool
Returns true
if this value is of type ScrollLock
. Returns false
otherwise
Sourcepub const fn is_num_lock(&self) -> bool
pub const fn is_num_lock(&self) -> bool
Returns true
if this value is of type NumLock
. Returns false
otherwise
Sourcepub const fn is_print_screen(&self) -> bool
pub const fn is_print_screen(&self) -> bool
Returns true
if this value is of type PrintScreen
. Returns false
otherwise
Sourcepub const fn is_pause(&self) -> bool
pub const fn is_pause(&self) -> bool
Returns true
if this value is of type Pause
. Returns false
otherwise
Returns true
if this value is of type Menu
. Returns false
otherwise
Sourcepub const fn is_keypad_begin(&self) -> bool
pub const fn is_keypad_begin(&self) -> bool
Returns true
if this value is of type KeypadBegin
. Returns false
otherwise
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<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> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string()
Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString
. Read more