Skip to main content

byteplug/controller/
keyboard.rs

1// Copyright (c) 2020 - Jonathan De Wachter
2//
3// This source file is part of the Byteplug framework which is released under the MIT license.
4// Please refer to the LICENSE file that can be found at the root of the project directory.
5//
6// Written by Jonathan De Wachter <dewachter.jonathan@gmail.com>, January 2020
7
8//! # Give access to the real-time state of the keyboard.
9//!
10//! Additional documentation is to be written here.
11
12use std::collections::HashMap;
13
14/// # Brief description.
15///
16/// The **Component struct** is not documented yet. Pull requests are welcome.
17///
18pub enum Direction {
19    Left, Right, Up, Down
20}
21
22/// # An enumeration of the keyboard keys.
23///
24/// Long description.
25///
26pub enum Key {
27    /// A letter key (A, B, C, ... up to Z)
28    Letter(char),
29    /// A number key (0, 1, 2, ... up to 9)
30    Number(u8),
31
32    /// The escape key
33    Escape,
34    /// A function key (F1, F2, F3, ... up to F24)
35    Function(u8),
36
37    /// The control key (left or right)
38    Control {
39        /// Left or right version of the key indicator
40        left: bool
41    },
42    /// The shift key (left or right)
43    Shift {
44        /// Left or right version of the key indicator
45        left: bool
46    },
47    /// The alternate key (left or right)
48    Alternate {
49        /// Left or right version of the key indicator
50        left: bool
51    },
52    /// The OS-specific key (named either 'Windows' or 'Command')
53    System,
54
55    /// One of the arrow key
56    Arrow {
57        /// The direction of the arrow (left, right, up or down)
58        direction: Direction
59    },
60
61    /// The ; key
62    Semilicon,
63    /// The , key
64    Comma,
65    /// The . key
66    Period,
67    /// The ' key
68    Quote,
69    /// The / key
70    Slash,
71    /// The \ key
72    Backslash,
73    /// The ~ key
74    Tilde,
75    /// The = key
76    Equal,
77    /// The - key
78    Hyphen,
79    /// The space key
80    Space,
81    /// The enter/return key
82    Enter,
83    /// The backspace key
84    Backspace,
85    /// The tabulation key
86    Tab,
87    /// The page up key
88    PageUp,
89    /// The page down key
90    PageDown,
91    /// The left bracket key
92    LeftBracket,
93    /// The right bracket key
94    RightBracket,
95
96    /// The menu key
97    Menu,
98    /// The end key
99    End,
100    /// The home key
101    Home,
102    /// The insert key
103    Insert,
104    /// The delete key
105    Delete,
106    /// The pause key
107    Pause,
108
109    /// A numpad number key (0, 1, 2, ... up to 9)
110    Numpad(u8),
111    /// The + key
112    Add,
113    /// The - key
114    Subtract,
115    /// The * key
116    Multiply,
117    /// The / key
118    Divide,
119
120    /// An unknown key (with its OS-specific identifier)
121    Unknown(u32)
122}
123
124/// # Brief description.
125///
126/// Long description.
127///
128pub struct Modifiers {
129  pub control: bool,
130  pub shift: bool,
131  pub alternate: bool,
132  pub system: bool
133}
134
135/// # Brief description.
136///
137/// Long description.
138///
139pub struct Keyboard {
140    pressed_keys: HashMap<Key, ()>
141}
142
143impl Keyboard {
144    /// Brief description.
145    ///
146    /// Long description.
147    ///
148    pub fn is_key_pressed(&self) -> bool {
149        false
150    }
151
152    /// Brief description.
153    ///
154    /// Long description.
155    ///
156    pub fn is_connected() -> bool {
157        false
158    }
159}