anathema_widgets/components/events/
key.rs1#[derive(Debug, Copy, Clone, PartialEq)]
2pub enum KeyState {
3 Press,
4 Repeat,
5 Release,
6}
7
8#[derive(Debug, Copy, Clone, PartialEq)]
9pub struct KeyEvent {
10 pub code: KeyCode,
11 pub ctrl: bool,
12 pub state: KeyState,
13}
14
15impl KeyEvent {
16 pub fn get_char(&self) -> Option<char> {
17 match self.code {
18 KeyCode::Char(c) => Some(c),
19 _ => None,
20 }
21 }
22
23 pub fn is_ctrl_c(&self) -> bool {
24 match self.code {
25 KeyCode::Char('c') => self.ctrl,
26 _ => false,
27 }
28 }
29}
30
31#[derive(Debug, Copy, Clone, PartialEq)]
32pub enum KeyCode {
33 Char(char),
34 Tab,
35 BackTab,
36 CtrlC,
37 Backspace,
38 Enter,
39 Left,
40 Right,
41 Up,
42 Down,
43 Home,
44 End,
45 PageUp,
46 PageDown,
47 Delete,
48 Insert,
49 F(u8),
50 Null,
51 Esc,
52 CapsLock,
53 ScrollLock,
54 NumLock,
55 PrintScreen,
56 Pause,
57 Menu,
58 KeypadBegin,
59}