135 lines
2.8 KiB
Rust
135 lines
2.8 KiB
Rust
use bitflags::*;
|
|
|
|
/// Which key is pressed. Not all of these are probable to appear
|
|
/// on most systems. A lot of this list is @wez trawling docs and
|
|
/// making an entry for things that might be possible in this first pass.
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub enum KeyCode {
|
|
/// The decoded unicode character
|
|
Char(char),
|
|
Composed(String),
|
|
|
|
Hyper,
|
|
Super,
|
|
Meta,
|
|
|
|
/// Ctrl-break on windows
|
|
Cancel,
|
|
// There is no `Backspace`; use `Char('\u{8}') instead
|
|
|
|
// There is no `Tab`; use `Char('\t')` instead
|
|
Clear,
|
|
// FIXME: Replace `Enter` with canonical Char(\n), but on
|
|
// windows we get \r. Figure out what other systems do.
|
|
Enter,
|
|
Shift,
|
|
// There is no `Escape`; use `Char('\u{1b}') instead
|
|
LeftShift,
|
|
RightShift,
|
|
Control,
|
|
LeftControl,
|
|
RightControl,
|
|
Alt,
|
|
LeftAlt,
|
|
RightAlt,
|
|
Pause,
|
|
CapsLock,
|
|
PageUp,
|
|
PageDown,
|
|
End,
|
|
Home,
|
|
LeftArrow,
|
|
RightArrow,
|
|
UpArrow,
|
|
DownArrow,
|
|
Select,
|
|
Print,
|
|
Execute,
|
|
PrintScreen,
|
|
Insert,
|
|
// There is no `Delete`; use `Char('\u{7f}')` instead
|
|
Help,
|
|
LeftWindows,
|
|
RightWindows,
|
|
Applications,
|
|
Sleep,
|
|
/// Numeric keypad digits 0-9
|
|
Numpad(u8),
|
|
Multiply,
|
|
Add,
|
|
Separator,
|
|
Subtract,
|
|
Decimal,
|
|
Divide,
|
|
/// F1-F24 are possible
|
|
Function(u8),
|
|
NumLock,
|
|
ScrollLock,
|
|
BrowserBack,
|
|
BrowserForward,
|
|
BrowserRefresh,
|
|
BrowserStop,
|
|
BrowserSearch,
|
|
BrowserFavorites,
|
|
BrowserHome,
|
|
VolumeMute,
|
|
VolumeDown,
|
|
VolumeUp,
|
|
MediaNextTrack,
|
|
MediaPrevTrack,
|
|
MediaStop,
|
|
MediaPlayPause,
|
|
ApplicationLeftArrow,
|
|
ApplicationRightArrow,
|
|
ApplicationUpArrow,
|
|
ApplicationDownArrow,
|
|
}
|
|
|
|
bitflags! {
|
|
#[derive(Default)]
|
|
pub struct Modifiers: u8 {
|
|
const NONE = 0;
|
|
const SHIFT = 1<<1;
|
|
const ALT = 1<<2;
|
|
const CTRL = 1<<3;
|
|
const SUPER = 1<<4;
|
|
}
|
|
}
|
|
bitflags! {
|
|
#[derive(Default)]
|
|
pub struct MouseButtons: u8 {
|
|
const NONE = 0;
|
|
const LEFT = 1<<1;
|
|
const RIGHT = 1<<2;
|
|
const MIDDLE = 1<<3;
|
|
const VERT_WHEEL = 1<<4;
|
|
const HORZ_WHEEL = 1<<5;
|
|
/// if set then the wheel movement was in the positive
|
|
/// direction, else the negative direction
|
|
const WHEEL_POSITIVE = 1<<6;
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
pub struct MouseEvent {
|
|
pub x: u16,
|
|
pub y: u16,
|
|
pub mouse_buttons: MouseButtons,
|
|
pub modifiers: Modifiers,
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
pub struct KeyEvent {
|
|
/// Which key was pressed
|
|
pub key: KeyCode,
|
|
|
|
/// Which modifiers are down
|
|
pub modifiers: Modifiers,
|
|
|
|
/// How many times this key repeats
|
|
pub repeat_count: u16,
|
|
|
|
/// If true, this is a key down rather than a key up event
|
|
pub key_is_down: bool,
|
|
}
|