hookmap_core/
button.rs

1//! Definition of keyboard and mouse button.
2
3use variant_count::VariantCount;
4
5/// A button input action.
6#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
7pub enum ButtonAction {
8    Press,
9    Release,
10}
11
12/// Indicates whether the button is on the keyboard or mouse.
13#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
14pub enum ButtonKind {
15    /// On the keyboard
16    Key,
17
18    /// On the mouse
19    Mouse,
20}
21
22/// Keyboard or mouse buttons.
23#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy, VariantCount)]
24pub enum Button {
25    LeftButton,
26    RightButton,
27    MiddleButton,
28    SideButton1,
29    SideButton2,
30
31    #[cfg(feature = "us-keyboard-layout")]
32    Tilde,
33    #[cfg(feature = "japanese-keyboard-layout")]
34    HankakuZenkaku,
35
36    Key1,
37    Key2,
38    Key3,
39    Key4,
40    Key5,
41    Key6,
42    Key7,
43    Key8,
44    Key9,
45    Key0,
46    Minus,
47
48    #[cfg(feature = "us-keyboard-layout")]
49    Equal,
50    #[cfg(feature = "japanese-keyboard-layout")]
51    Hat,
52
53    #[cfg(feature = "japanese-keyboard-layout")]
54    Yen,
55
56    Backspace,
57    Tab,
58    Q,
59    W,
60    E,
61    R,
62    T,
63    Y,
64    U,
65    I,
66    O,
67    P,
68
69    #[cfg(feature = "us-keyboard-layout")]
70    OpenSquareBracket,
71    #[cfg(feature = "japanese-keyboard-layout")]
72    At,
73
74    #[cfg(feature = "us-keyboard-layout")]
75    CloseSquareBracket,
76    #[cfg(feature = "japanese-keyboard-layout")]
77    OpenSquareBracket,
78
79    #[cfg(feature = "us-keyboard-layout")]
80    CapsLock,
81    #[cfg(feature = "japanese-keyboard-layout")]
82    Eisu,
83
84    A,
85    S,
86    D,
87    F,
88    G,
89    H,
90    J,
91    K,
92    L,
93
94    #[cfg(feature = "us-keyboard-layout")]
95    SemiColon,
96    #[cfg(feature = "japanese-keyboard-layout")]
97    SemiColon,
98
99    #[cfg(feature = "us-keyboard-layout")]
100    SingleQuote,
101    #[cfg(feature = "japanese-keyboard-layout")]
102    Colon,
103
104    #[cfg(feature = "japanese-keyboard-layout")]
105    CloseSquareBracket,
106
107    Enter,
108    LShift,
109    Z,
110    X,
111    C,
112    V,
113    B,
114    N,
115    M,
116    Comma,
117    Dot,
118    Slash,
119
120    #[cfg(feature = "japanese-keyboard-layout")]
121    BackSlash,
122
123    RShift,
124    LCtrl,
125    LSuper,
126    LAlt,
127
128    #[cfg(feature = "japanese-keyboard-layout")]
129    Muhenkan,
130
131    Space,
132
133    #[cfg(feature = "japanese-keyboard-layout")]
134    Henkan,
135
136    #[cfg(feature = "japanese-keyboard-layout")]
137    KatakanaHiragana,
138
139    RAlt,
140    RSuper,
141    Application,
142    RCtrl,
143    Insert,
144    Delete,
145    LeftArrow,
146    Home,
147    End,
148    UpArrow,
149    DownArrow,
150    PageUp,
151    PageDown,
152    RightArrow,
153    Numpad1,
154    Numpad2,
155    Numpad3,
156    Numpad4,
157    Numpad5,
158    Numpad6,
159    Numpad7,
160    Numpad8,
161    Numpad9,
162    Numpad0,
163    NumpadDot,
164    NumpadSlash,
165    NumpadAsterisk,
166    NumpadMinus,
167    NumpadPlus,
168    Esc,
169    F1,
170    F2,
171    F3,
172    F4,
173    F5,
174    F6,
175    F7,
176    F8,
177    F9,
178    F10,
179    F11,
180    F12,
181    F13,
182    F14,
183    F15,
184    F16,
185    F17,
186    F18,
187    F19,
188    F20,
189    F21,
190    F22,
191    F23,
192    F24,
193    PrintScreen,
194
195    VolumeMute,
196    VolumeDown,
197    VolumeUp,
198    MediaNext,
199    MediaPrevious,
200    MediaStop,
201    MediaPlayPause,
202
203    Shift,
204    Ctrl,
205    Alt,
206    Super,
207}
208
209impl Button {
210    pub fn kind(&self) -> ButtonKind {
211        match self {
212            Button::LeftButton
213            | Button::RightButton
214            | Button::MiddleButton
215            | Button::SideButton1
216            | Button::SideButton2 => ButtonKind::Mouse,
217            _ => ButtonKind::Key,
218        }
219    }
220}