espanso/espanso-detect/src/event.rs

136 lines
2.4 KiB
Rust
Raw Normal View History

2021-01-29 20:55:47 +00:00
/*
* This file is part of espanso.
*
* Copyright (C) 2019-2021 Federico Terzi
*
* espanso is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* espanso is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
*/
2021-01-29 21:24:24 +00:00
#[cfg(test)]
use enum_as_inner::EnumAsInner;
#[derive(Debug, PartialEq)]
#[cfg_attr(test, derive(EnumAsInner))]
2021-01-29 20:55:47 +00:00
pub enum InputEvent {
Mouse(MouseEvent),
Keyboard(KeyboardEvent),
2021-03-14 14:50:54 +00:00
HotKey(HotKeyEvent),
// Special event type only used on macOS
// This is sent after a global keyboard shortcut is released
// See https://github.com/federico-terzi/espanso/issues/791
AllModifiersReleased,
2021-01-29 20:55:47 +00:00
}
2021-01-29 21:24:24 +00:00
#[derive(Debug, PartialEq)]
2021-01-29 20:55:47 +00:00
pub enum MouseButton {
Left,
Right,
Middle,
Button1,
Button2,
Button3,
Button4,
Button5,
}
2021-01-29 21:24:24 +00:00
#[derive(Debug, PartialEq)]
2021-01-29 20:55:47 +00:00
pub struct MouseEvent {
pub button: MouseButton,
pub status: Status,
}
2021-01-29 21:24:24 +00:00
#[derive(Debug, PartialEq)]
2021-01-29 20:55:47 +00:00
pub enum Status {
Pressed,
Released,
}
2021-01-29 21:24:24 +00:00
#[derive(Debug, PartialEq)]
2021-01-29 20:55:47 +00:00
pub enum Variant {
Left,
Right,
}
2021-01-29 21:24:24 +00:00
#[derive(Debug, PartialEq)]
2021-01-29 20:55:47 +00:00
pub struct KeyboardEvent {
pub key: Key,
pub value: Option<String>,
pub status: Status,
pub variant: Option<Variant>,
pub code: u32,
2021-01-29 20:55:47 +00:00
}
// A subset of the Web's key values: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values
2021-01-29 21:24:24 +00:00
#[derive(Debug, PartialEq)]
2021-01-29 20:55:47 +00:00
pub enum Key {
// Modifiers
Alt,
CapsLock,
Control,
Meta,
NumLock,
Shift,
// Whitespace
Enter,
Tab,
Space,
// Navigation
ArrowDown,
ArrowLeft,
ArrowRight,
ArrowUp,
End,
Home,
PageDown,
PageUp,
2021-02-09 16:12:16 +00:00
// UI
Escape,
2021-01-29 20:55:47 +00:00
// Editing keys
Backspace,
// Function keys
F1,
F2,
F3,
F4,
F5,
F6,
F7,
F8,
F9,
F10,
F11,
F12,
F13,
F14,
F15,
F16,
F17,
F18,
F19,
F20,
// Other keys, includes the raw code provided by the operating system
Other(i32),
}
2021-03-14 14:50:54 +00:00
#[derive(Debug, PartialEq)]
pub struct HotKeyEvent {
pub hotkey_id: i32,
2021-03-15 18:08:08 +00:00
}