bones_framework/input/
keyboard.rs

1//! Keyboard input resource.
2
3use crate::prelude::*;
4
5/// Resource containing the keyboard input events detected on the current frame.
6#[derive(HasSchema, Clone, Debug, Default)]
7#[repr(C)]
8pub struct KeyboardInputs {
9    /// The key events that have been detected this frame.
10    pub key_events: SVec<KeyboardEvent>,
11}
12
13/// A keyboard input event.
14#[derive(HasSchema, Clone, Copy, Debug, Default)]
15#[repr(C)]
16pub struct KeyboardEvent {
17    /// The scan code of the pressed key.
18    pub scan_code: u32,
19    /// The key code of the pressed key, if applicable.
20    pub key_code: Maybe<KeyCode>,
21    /// The state of the keyboard button.
22    pub button_state: ButtonState,
23}
24
25/// The key code of a keyboard key.
26#[derive(
27    HasSchema,
28    Clone,
29    Copy,
30    Default,
31    Debug,
32    PartialEq,
33    Eq,
34    Hash,
35    serde::Deserialize,
36    serde::Serialize,
37)]
38#[repr(u32)]
39pub enum KeyCode {
40    #[default]
41    /// The `1` key over the letters.
42    Key1,
43    /// The `2` key over the letters.
44    Key2,
45    /// The `3` key over the letters.
46    Key3,
47    /// The `4` key over the letters.
48    Key4,
49    /// The `5` key over the letters.
50    Key5,
51    /// The `6` key over the letters.
52    Key6,
53    /// The `7` key over the letters.
54    Key7,
55    /// The `8` key over the letters.
56    Key8,
57    /// The `9` key over the letters.
58    Key9,
59    /// The `0` key over the letters.
60    Key0,
61
62    /// The `A` key.
63    A,
64    /// The `B` key.
65    B,
66    /// The `C` key.
67    C,
68    /// The `D` key.
69    D,
70    /// The `E` key.
71    E,
72    /// The `F` key.
73    F,
74    /// The `G` key.
75    G,
76    /// The `H` key.
77    H,
78    /// The `I` key.
79    I,
80    /// The `J` key.
81    J,
82    /// The `K` key.
83    K,
84    /// The `L` key.
85    L,
86    /// The `M` key.
87    M,
88    /// The `N` key.
89    N,
90    /// The `O` key.
91    O,
92    /// The `P` key.
93    P,
94    /// The `Q` key.
95    Q,
96    /// The `R` key.
97    R,
98    /// The `S` key.
99    S,
100    /// The `T` key.
101    T,
102    /// The `U` key.
103    U,
104    /// The `V` key.
105    V,
106    /// The `W` key.
107    W,
108    /// The `X` key.
109    X,
110    /// The `Y` key.
111    Y,
112    /// The `Z` key.
113    Z,
114
115    /// The `Escape` / `ESC` key, next to the `F1` key.
116    Escape,
117
118    /// The `F1` key.
119    F1,
120    /// The `F2` key.
121    F2,
122    /// The `F3` key.
123    F3,
124    /// The `F4` key.
125    F4,
126    /// The `F5` key.
127    F5,
128    /// The `F6` key.
129    F6,
130    /// The `F7` key.
131    F7,
132    /// The `F8` key.
133    F8,
134    /// The `F9` key.
135    F9,
136    /// The `F10` key.
137    F10,
138    /// The `F11` key.
139    F11,
140    /// The `F12` key.
141    F12,
142    /// The `F13` key.
143    F13,
144    /// The `F14` key.
145    F14,
146    /// The `F15` key.
147    F15,
148    /// The `F16` key.
149    F16,
150    /// The `F17` key.
151    F17,
152    /// The `F18` key.
153    F18,
154    /// The `F19` key.
155    F19,
156    /// The `F20` key.
157    F20,
158    /// The `F21` key.
159    F21,
160    /// The `F22` key.
161    F22,
162    /// The `F23` key.
163    F23,
164    /// The `F24` key.
165    F24,
166
167    /// The `Snapshot` / `Print Screen` key.
168    Snapshot,
169    /// The `Scroll` / `Scroll Lock` key.
170    Scroll,
171    /// The `Pause` / `Break` key, next to the `Scroll` key.
172    Pause,
173
174    /// The `Insert` key, next to the `Backspace` key.
175    Insert,
176    /// The `Home` key.
177    Home,
178    /// The `Delete` key.
179    Delete,
180    /// The `End` key.
181    End,
182    /// The `PageDown` key.
183    PageDown,
184    /// The `PageUp` key.
185    PageUp,
186
187    /// The `Left` / `Left Arrow` key.
188    Left,
189    /// The `Up` / `Up Arrow` key.
190    Up,
191    /// The `Right` / `Right Arrow` key.
192    Right,
193    /// The `Down` / `Down Arrow` key.
194    Down,
195
196    /// The `Back` / `Backspace` key.
197    Back,
198    /// The `Return` / `Enter` key.
199    Return,
200    /// The `Space` / `Spacebar` / ` ` key.
201    Space,
202
203    /// The `Compose` key on Linux.
204    Compose,
205    /// The `Caret` / `^` key.
206    Caret,
207
208    /// The `Numlock` key.
209    Numlock,
210    /// The `Numpad0` / `0` key.
211    Numpad0,
212    /// The `Numpad1` / `1` key.
213    Numpad1,
214    /// The `Numpad2` / `2` key.
215    Numpad2,
216    /// The `Numpad3` / `3` key.
217    Numpad3,
218    /// The `Numpad4` / `4` key.
219    Numpad4,
220    /// The `Numpad5` / `5` key.
221    Numpad5,
222    /// The `Numpad6` / `6` key.
223    Numpad6,
224    /// The `Numpad7` / `7` key.
225    Numpad7,
226    /// The `Numpad8` / `8` key.
227    Numpad8,
228    /// The `Numpad9` / `9` key.
229    Numpad9,
230
231    /// The `AbntC1` key.
232    AbntC1,
233    /// The `AbntC2` key.
234    AbntC2,
235
236    /// The `NumpadAdd` / `+` key.
237    NumpadAdd,
238    /// The `Apostrophe` / `'` key.
239    Apostrophe,
240    /// The `Apps` key.
241    Apps,
242    /// The `Asterisk` / `*` key.
243    Asterisk,
244    /// The `Plus` / `+` key.
245    Plus,
246    /// The `At` / `@` key.
247    At,
248    /// The `Ax` key.
249    Ax,
250    /// The `Backslash` / `\` key.
251    Backslash,
252    /// The `Calculator` key.
253    Calculator,
254    /// The `Capital` key.
255    Capital,
256    /// The `Colon` / `:` key.
257    Colon,
258    /// The `Comma` / `,` key.
259    Comma,
260    /// The `Convert` key.
261    Convert,
262    /// The `NumpadDecimal` / `.` key.
263    NumpadDecimal,
264    /// The `NumpadDivide` / `/` key.
265    NumpadDivide,
266    /// The `Equals` / `=` key.
267    Equals,
268    /// The `Grave` / `Backtick` / `` ` `` key.
269    Grave,
270    /// The `Kana` key.
271    Kana,
272    /// The `Kanji` key.
273    Kanji,
274
275    /// The `Left Alt` key. Maps to `Left Option` on Mac.
276    AltLeft,
277    /// The `Left Bracket` / `[` key.
278    BracketLeft,
279    /// The `Left Control` key.
280    ControlLeft,
281    /// The `Left Shift` key.
282    ShiftLeft,
283    /// The `Left Super` key.
284    /// Generic keyboards usually display this key with the *Microsoft Windows* logo.
285    /// Apple keyboards call this key the *Command Key* and display it using the ⌘ character.
286    #[doc(alias("LWin", "LMeta", "LLogo"))]
287    SuperLeft,
288
289    /// The `Mail` key.
290    Mail,
291    /// The `MediaSelect` key.
292    MediaSelect,
293    /// The `MediaStop` key.
294    MediaStop,
295    /// The `Minus` / `-` key.
296    Minus,
297    /// The `NumpadMultiply` / `*` key.
298    NumpadMultiply,
299    /// The `Mute` key.
300    Mute,
301    /// The `MyComputer` key.
302    MyComputer,
303    /// The `NavigateForward` / `Prior` key.
304    NavigateForward,
305    /// The `NavigateBackward` / `Next` key.
306    NavigateBackward,
307    /// The `NextTrack` key.
308    NextTrack,
309    /// The `NoConvert` key.
310    NoConvert,
311    /// The `NumpadComma` / `,` key.
312    NumpadComma,
313    /// The `NumpadEnter` key.
314    NumpadEnter,
315    /// The `NumpadEquals` / `=` key.
316    NumpadEquals,
317    /// The `Oem102` key.
318    Oem102,
319    /// The `Period` / `.` key.
320    Period,
321    /// The `PlayPause` key.
322    PlayPause,
323    /// The `Power` key.
324    Power,
325    /// The `PrevTrack` key.
326    PrevTrack,
327
328    /// The `Right Alt` key. Maps to `Right Option` on Mac.
329    AltRight,
330    /// The `Right Bracket` / `]` key.
331    BracketRight,
332    /// The `Right Control` key.
333    ControlRight,
334    /// The `Right Shift` key.
335    ShiftRight,
336    /// The `Right Super` key.
337    /// Generic keyboards usually display this key with the *Microsoft Windows* logo.
338    /// Apple keyboards call this key the *Command Key* and display it using the ⌘ character.
339    #[doc(alias("RWin", "RMeta", "RLogo"))]
340    SuperRight,
341
342    /// The `Semicolon` / `;` key.
343    Semicolon,
344    /// The `Slash` / `/` key.
345    Slash,
346    /// The `Sleep` key.
347    Sleep,
348    /// The `Stop` key.
349    Stop,
350    /// The `NumpadSubtract` / `-` key.
351    NumpadSubtract,
352    /// The `Sysrq` key.
353    Sysrq,
354    /// The `Tab` / `   ` key.
355    Tab,
356    /// The `Underline` / `_` key.
357    Underline,
358    /// The `Unlabeled` key.
359    Unlabeled,
360
361    /// The `VolumeDown` key.
362    VolumeDown,
363    /// The `VolumeUp` key.
364    VolumeUp,
365
366    /// The `Wake` key.
367    Wake,
368
369    /// The `WebBack` key.
370    WebBack,
371    /// The `WebFavorites` key.
372    WebFavorites,
373    /// The `WebForward` key.
374    WebForward,
375    /// The `WebHome` key.
376    WebHome,
377    /// The `WebRefresh` key.
378    WebRefresh,
379    /// The `WebSearch` key.
380    WebSearch,
381    /// The `WebStop` key.
382    WebStop,
383
384    /// The `Yen` key.
385    Yen,
386
387    /// The `Copy` key.
388    Copy,
389    /// The `Paste` key.
390    Paste,
391    /// The `Cut` key.
392    Cut,
393}