1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use super::*;
#[derive(Clone, Copy, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct KeyEvent {
pub character: char,
pub key_code: KeyCode,
pub modifiers: ControlKeyState,
pub pressed: bool,
pub repeat_count: u16,
pub scan_code: u16,
}
impl KeyEvent {
pub fn new() -> KeyEvent {
KeyEvent {
character: '\0',
modifiers: ControlKeyState::default(),
key_code: KeyCode::None,
pressed: false,
repeat_count: 0,
scan_code: 0,
}
}
}
impl Into<InputEvent> for KeyEvent {
fn into(self) -> InputEvent {
if self.pressed {
InputEvent::KeyDown(self)
} else {
InputEvent::KeyUp(self)
}
}
}