1use crate::Modifiers;
2
3#[derive(Clone, Debug, Default)]
4pub struct KeyboardEvent {
5 pub pressed: bool,
6 pub key: Option<Key>,
7 pub text: Option<char>,
8 pub modifiers: Modifiers,
9}
10
11impl KeyboardEvent {
12 pub fn is_pressed(&self, key: Key) -> bool {
13 self.pressed && self.key == Some(key)
14 }
15
16 pub fn is_released(&self, key: Key) -> bool {
17 !self.pressed && self.key == Some(key)
18 }
19
20 pub fn is_press(&self) -> bool {
21 self.pressed && self.key.is_some()
22 }
23
24 pub fn is_release(&self) -> bool {
25 !self.pressed && self.key.is_some()
26 }
27}
28
29#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
30pub enum Key {
31 A,
32 B,
33 C,
34 D,
35 E,
36 F,
37 G,
38 H,
39 I,
40 J,
41 K,
42 L,
43 M,
44 N,
45 O,
46 P,
47 Q,
48 R,
49 S,
50 T,
51 U,
52 V,
53 W,
54 X,
55 Y,
56 Z,
57 Key0,
58 Key1,
59 Key2,
60 Key3,
61 Key4,
62 Key5,
63 Key6,
64 Key7,
65 Key8,
66 Key9,
67 Num0,
68 Num1,
69 Num2,
70 Num3,
71 Num4,
72 Num5,
73 Num6,
74 Num7,
75 Num8,
76 Num9,
77 F1,
78 F2,
79 F3,
80 F4,
81 F5,
82 F6,
83 F7,
84 F8,
85 F9,
86 F10,
87 F11,
88 F12,
89 Escape,
90 Tab,
91 Space,
92 Backspace,
93 Enter,
94 Insert,
95 Delete,
96 Home,
97 End,
98 PageUp,
99 PageDown,
100 Left,
101 Right,
102 Up,
103 Down,
104 CapsLock,
105 ScrollLock,
106 NumLock,
107 PrintScreen,
108 Pause,
109 LeftShift,
110 RightShift,
111 LeftCtrl,
112 RightCtrl,
113 LeftAlt,
114 RightAlt,
115 LeftMeta,
116 Menu,
117}