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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
use crate::{sf_bool_ext::SfBoolExt, window::thread_safety};
use csfml_window_sys as ffi;
#[repr(transparent)]
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Copy, Hash)]
pub struct Key(pub(super) ffi::sfKeyCode);
impl Key {
pub const UNKNOWN: Self = Self(ffi::sfKeyCode_sfKeyUnknown);
pub const A: Self = Self(ffi::sfKeyCode_sfKeyA);
pub const B: Self = Self(ffi::sfKeyCode_sfKeyB);
pub const C: Self = Self(ffi::sfKeyCode_sfKeyC);
pub const D: Self = Self(ffi::sfKeyCode_sfKeyD);
pub const E: Self = Self(ffi::sfKeyCode_sfKeyE);
pub const F: Self = Self(ffi::sfKeyCode_sfKeyF);
pub const G: Self = Self(ffi::sfKeyCode_sfKeyG);
pub const H: Self = Self(ffi::sfKeyCode_sfKeyH);
pub const I: Self = Self(ffi::sfKeyCode_sfKeyI);
pub const J: Self = Self(ffi::sfKeyCode_sfKeyJ);
pub const K: Self = Self(ffi::sfKeyCode_sfKeyK);
pub const L: Self = Self(ffi::sfKeyCode_sfKeyL);
pub const M: Self = Self(ffi::sfKeyCode_sfKeyM);
pub const N: Self = Self(ffi::sfKeyCode_sfKeyN);
pub const O: Self = Self(ffi::sfKeyCode_sfKeyO);
pub const P: Self = Self(ffi::sfKeyCode_sfKeyP);
pub const Q: Self = Self(ffi::sfKeyCode_sfKeyQ);
pub const R: Self = Self(ffi::sfKeyCode_sfKeyR);
pub const S: Self = Self(ffi::sfKeyCode_sfKeyS);
pub const T: Self = Self(ffi::sfKeyCode_sfKeyT);
pub const U: Self = Self(ffi::sfKeyCode_sfKeyU);
pub const V: Self = Self(ffi::sfKeyCode_sfKeyV);
pub const W: Self = Self(ffi::sfKeyCode_sfKeyW);
pub const X: Self = Self(ffi::sfKeyCode_sfKeyX);
pub const Y: Self = Self(ffi::sfKeyCode_sfKeyY);
pub const Z: Self = Self(ffi::sfKeyCode_sfKeyZ);
pub const NUM0: Self = Self(ffi::sfKeyCode_sfKeyNum0);
pub const NUM1: Self = Self(ffi::sfKeyCode_sfKeyNum1);
pub const NUM2: Self = Self(ffi::sfKeyCode_sfKeyNum2);
pub const NUM3: Self = Self(ffi::sfKeyCode_sfKeyNum3);
pub const NUM4: Self = Self(ffi::sfKeyCode_sfKeyNum4);
pub const NUM5: Self = Self(ffi::sfKeyCode_sfKeyNum5);
pub const NUM6: Self = Self(ffi::sfKeyCode_sfKeyNum6);
pub const NUM7: Self = Self(ffi::sfKeyCode_sfKeyNum7);
pub const NUM8: Self = Self(ffi::sfKeyCode_sfKeyNum8);
pub const NUM9: Self = Self(ffi::sfKeyCode_sfKeyNum9);
pub const ESCAPE: Self = Self(ffi::sfKeyCode_sfKeyEscape);
pub const LCONTROL: Self = Self(ffi::sfKeyCode_sfKeyLControl);
pub const LSHIFT: Self = Self(ffi::sfKeyCode_sfKeyLShift);
pub const LALT: Self = Self(ffi::sfKeyCode_sfKeyLAlt);
pub const LSYSTEM: Self = Self(ffi::sfKeyCode_sfKeyLSystem);
pub const RCONTROL: Self = Self(ffi::sfKeyCode_sfKeyRControl);
pub const RSHIFT: Self = Self(ffi::sfKeyCode_sfKeyRShift);
pub const RALT: Self = Self(ffi::sfKeyCode_sfKeyRAlt);
pub const RSYSTEM: Self = Self(ffi::sfKeyCode_sfKeyRSystem);
pub const MENU: Self = Self(ffi::sfKeyCode_sfKeyMenu);
pub const LBRACKET: Self = Self(ffi::sfKeyCode_sfKeyLBracket);
pub const RBRACKET: Self = Self(ffi::sfKeyCode_sfKeyRBracket);
pub const SEMICOLON: Self = Self(ffi::sfKeyCode_sfKeySemicolon);
pub const COMMA: Self = Self(ffi::sfKeyCode_sfKeyComma);
pub const PERIOD: Self = Self(ffi::sfKeyCode_sfKeyPeriod);
pub const QUOTE: Self = Self(ffi::sfKeyCode_sfKeyQuote);
pub const SLASH: Self = Self(ffi::sfKeyCode_sfKeySlash);
pub const BACKSLASH: Self = Self(ffi::sfKeyCode_sfKeyBackslash);
pub const TILDE: Self = Self(ffi::sfKeyCode_sfKeyTilde);
pub const EQUAL: Self = Self(ffi::sfKeyCode_sfKeyEqual);
pub const HYPHEN: Self = Self(ffi::sfKeyCode_sfKeyHyphen);
pub const SPACE: Self = Self(ffi::sfKeyCode_sfKeySpace);
pub const ENTER: Self = Self(ffi::sfKeyCode_sfKeyEnter);
pub const BACKSPACE: Self = Self(ffi::sfKeyCode_sfKeyBackspace);
pub const TAB: Self = Self(ffi::sfKeyCode_sfKeyTab);
pub const PAGEUP: Self = Self(ffi::sfKeyCode_sfKeyPageUp);
pub const PAGEDOWN: Self = Self(ffi::sfKeyCode_sfKeyPageDown);
pub const END: Self = Self(ffi::sfKeyCode_sfKeyEnd);
pub const HOME: Self = Self(ffi::sfKeyCode_sfKeyHome);
pub const INSERT: Self = Self(ffi::sfKeyCode_sfKeyInsert);
pub const DELETE: Self = Self(ffi::sfKeyCode_sfKeyDelete);
pub const ADD: Self = Self(ffi::sfKeyCode_sfKeyAdd);
pub const SUBTRACT: Self = Self(ffi::sfKeyCode_sfKeySubtract);
pub const MULTIPLY: Self = Self(ffi::sfKeyCode_sfKeyMultiply);
pub const DIVIDE: Self = Self(ffi::sfKeyCode_sfKeyDivide);
pub const LEFT: Self = Self(ffi::sfKeyCode_sfKeyLeft);
pub const RIGHT: Self = Self(ffi::sfKeyCode_sfKeyRight);
pub const UP: Self = Self(ffi::sfKeyCode_sfKeyUp);
pub const DOWN: Self = Self(ffi::sfKeyCode_sfKeyDown);
pub const NUMPAD0: Self = Self(ffi::sfKeyCode_sfKeyNumpad0);
pub const NUMPAD1: Self = Self(ffi::sfKeyCode_sfKeyNumpad1);
pub const NUMPAD2: Self = Self(ffi::sfKeyCode_sfKeyNumpad2);
pub const NUMPAD3: Self = Self(ffi::sfKeyCode_sfKeyNumpad3);
pub const NUMPAD4: Self = Self(ffi::sfKeyCode_sfKeyNumpad4);
pub const NUMPAD5: Self = Self(ffi::sfKeyCode_sfKeyNumpad5);
pub const NUMPAD6: Self = Self(ffi::sfKeyCode_sfKeyNumpad6);
pub const NUMPAD7: Self = Self(ffi::sfKeyCode_sfKeyNumpad7);
pub const NUMPAD8: Self = Self(ffi::sfKeyCode_sfKeyNumpad8);
pub const NUMPAD9: Self = Self(ffi::sfKeyCode_sfKeyNumpad9);
pub const F1: Self = Self(ffi::sfKeyCode_sfKeyF1);
pub const F2: Self = Self(ffi::sfKeyCode_sfKeyF2);
pub const F3: Self = Self(ffi::sfKeyCode_sfKeyF3);
pub const F4: Self = Self(ffi::sfKeyCode_sfKeyF4);
pub const F5: Self = Self(ffi::sfKeyCode_sfKeyF5);
pub const F6: Self = Self(ffi::sfKeyCode_sfKeyF6);
pub const F7: Self = Self(ffi::sfKeyCode_sfKeyF7);
pub const F8: Self = Self(ffi::sfKeyCode_sfKeyF8);
pub const F9: Self = Self(ffi::sfKeyCode_sfKeyF9);
pub const F10: Self = Self(ffi::sfKeyCode_sfKeyF10);
pub const F11: Self = Self(ffi::sfKeyCode_sfKeyF11);
pub const F12: Self = Self(ffi::sfKeyCode_sfKeyF12);
pub const F13: Self = Self(ffi::sfKeyCode_sfKeyF13);
pub const F14: Self = Self(ffi::sfKeyCode_sfKeyF14);
pub const F15: Self = Self(ffi::sfKeyCode_sfKeyF15);
pub const PAUSE: Self = Self(ffi::sfKeyCode_sfKeyPause);
pub const COUNT: Self = Self(ffi::sfKeyCode_sfKeyCount);
}
impl Key {
#[must_use]
pub fn is_pressed(self) -> bool {
thread_safety::set_window_thread();
unsafe { ffi::sfKeyboard_isKeyPressed(self.0) }.into_bool()
}
}
pub fn set_virtual_keyboard_visible(visible: bool) {
unsafe { ffi::sfKeyboard_setVirtualKeyboardVisible(SfBoolExt::from_bool(visible)) }
}