#[cfg(feature = "recorder")]
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(u16)]
#[cfg_attr(feature = "recorder", derive(Serialize, Deserialize))]
pub enum Key {
KeyA,
KeyB,
KeyC,
KeyD,
KeyE,
KeyF,
KeyG,
KeyH,
KeyI,
KeyJ,
KeyK,
KeyL,
KeyM,
KeyN,
KeyO,
KeyP,
KeyQ,
KeyR,
KeyS,
KeyT,
KeyU,
KeyV,
KeyW,
KeyX,
KeyY,
KeyZ,
Num0,
Num1,
Num2,
Num3,
Num4,
Num5,
Num6,
Num7,
Num8,
Num9,
F1,
F2,
F3,
F4,
F5,
F6,
F7,
F8,
F9,
F10,
F11,
F12,
F13,
F14,
F15,
F16,
F17,
F18,
F19,
F20,
F21,
F22,
F23,
F24,
ShiftLeft,
ShiftRight,
ControlLeft,
ControlRight,
AltLeft,
AltRight,
MetaLeft, MetaRight,
Escape,
Tab,
CapsLock,
Space,
Enter,
Backspace,
Insert,
Delete,
Home,
End,
PageUp,
PageDown,
ArrowUp,
ArrowDown,
ArrowLeft,
ArrowRight,
NumLock,
ScrollLock,
PrintScreen,
Pause,
Grave, Minus, Equal, BracketLeft, BracketRight, Backslash, Semicolon, Quote, Comma, Period, Slash,
Numpad0,
Numpad1,
Numpad2,
Numpad3,
Numpad4,
Numpad5,
Numpad6,
Numpad7,
Numpad8,
Numpad9,
NumpadAdd,
NumpadSubtract,
NumpadMultiply,
NumpadDivide,
NumpadDecimal,
NumpadEnter,
NumpadEqual,
VolumeUp,
VolumeDown,
VolumeMute,
MediaPlayPause,
MediaStop,
MediaNext,
MediaPrevious,
BrowserBack,
BrowserForward,
BrowserRefresh,
BrowserStop,
BrowserSearch,
BrowserFavorites,
BrowserHome,
LaunchMail,
LaunchApp1,
LaunchApp2,
IntlBackslash,
IntlYen,
IntlRo,
ContextMenu,
Unknown(u32),
}
impl Key {
pub fn is_modifier(&self) -> bool {
matches!(
self,
Key::ShiftLeft
| Key::ShiftRight
| Key::ControlLeft
| Key::ControlRight
| Key::AltLeft
| Key::AltRight
| Key::MetaLeft
| Key::MetaRight
)
}
pub fn is_letter(&self) -> bool {
matches!(
self,
Key::KeyA
| Key::KeyB
| Key::KeyC
| Key::KeyD
| Key::KeyE
| Key::KeyF
| Key::KeyG
| Key::KeyH
| Key::KeyI
| Key::KeyJ
| Key::KeyK
| Key::KeyL
| Key::KeyM
| Key::KeyN
| Key::KeyO
| Key::KeyP
| Key::KeyQ
| Key::KeyR
| Key::KeyS
| Key::KeyT
| Key::KeyU
| Key::KeyV
| Key::KeyW
| Key::KeyX
| Key::KeyY
| Key::KeyZ
)
}
pub fn is_number(&self) -> bool {
matches!(
self,
Key::Num0
| Key::Num1
| Key::Num2
| Key::Num3
| Key::Num4
| Key::Num5
| Key::Num6
| Key::Num7
| Key::Num8
| Key::Num9
)
}
pub fn is_function_key(&self) -> bool {
matches!(
self,
Key::F1
| Key::F2
| Key::F3
| Key::F4
| Key::F5
| Key::F6
| Key::F7
| Key::F8
| Key::F9
| Key::F10
| Key::F11
| Key::F12
| Key::F13
| Key::F14
| Key::F15
| Key::F16
| Key::F17
| Key::F18
| Key::F19
| Key::F20
| Key::F21
| Key::F22
| Key::F23
| Key::F24
)
}
pub fn is_numpad(&self) -> bool {
matches!(
self,
Key::Numpad0
| Key::Numpad1
| Key::Numpad2
| Key::Numpad3
| Key::Numpad4
| Key::Numpad5
| Key::Numpad6
| Key::Numpad7
| Key::Numpad8
| Key::Numpad9
| Key::NumpadAdd
| Key::NumpadSubtract
| Key::NumpadMultiply
| Key::NumpadDivide
| Key::NumpadDecimal
| Key::NumpadEnter
| Key::NumpadEqual
)
}
pub fn is_media(&self) -> bool {
matches!(
self,
Key::VolumeUp
| Key::VolumeDown
| Key::VolumeMute
| Key::MediaPlayPause
| Key::MediaStop
| Key::MediaNext
| Key::MediaPrevious
)
}
pub fn is_navigation(&self) -> bool {
matches!(
self,
Key::ArrowUp
| Key::ArrowDown
| Key::ArrowLeft
| Key::ArrowRight
| Key::Home
| Key::End
| Key::PageUp
| Key::PageDown
)
}
}
impl Default for Key {
fn default() -> Self {
Key::Unknown(0)
}
}