use bitflags::bitflags;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct KeyEvent {
pub code: KeyCode,
pub modifiers: KeyModifiers,
pub kind: KeyEventKind,
pub state: KeyEventState,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum KeyCode {
Char(char),
F(u8),
Backspace,
Enter,
Up,
Down,
Left,
Right,
Home,
End,
PageUp,
PageDown,
Tab,
BackTab,
Delete,
Insert,
Null,
Esc,
CapsLock,
ScrollLock,
NumLock,
PrintScreen,
Pause,
Menu,
KeypadBegin,
Media(MediaKeyCode),
Modifier(ModifierKeyCode),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum MediaKeyCode {
Play,
Pause,
PlayPause,
Reverse,
Stop,
FastForward,
Rewind,
TrackNext,
TrackPrevious,
Record,
LowerVolume,
RaiseVolume,
MuteVolume,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ModifierKeyCode {
LeftShift,
LeftControl,
LeftAlt,
LeftSuper,
LeftHyper,
LeftMeta,
RightShift,
RightControl,
RightAlt,
RightSuper,
RightHyper,
RightMeta,
IsoLevel3Shift,
IsoLevel5Shift,
}
bitflags! {
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct KeyModifiers: u8 {
const NONE = 0b0000_0000;
const SHIFT = 0b0000_0001;
const CONTROL = 0b0000_0010;
const ALT = 0b0000_0100;
const SUPER = 0b0000_1000;
const HYPER = 0b0001_0000;
const META = 0b0010_0000;
}
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum KeyEventKind {
Press,
Repeat,
Release,
}
bitflags! {
#[derive(Debug,Clone, Eq, PartialEq)]
pub struct KeyEventState: u8 {
const NONE = 0b0000_0000;
const KEYPAD = 0b0000_0001;
const CAPS_LOCK = 0b0000_0010;
const NUM_LOCK = 0b0000_0100;
}
}