Loading...
Searching...
No Matches
Keyboard.hpp
Go to the documentation of this file.
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2024 Laurent Gomila (laurent@sfml-dev.org)
5//
6// This software is provided 'as-is', without any express or implied warranty.
7// In no event will the authors be held liable for any damages arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it freely,
11// subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented;
14// you must not claim that you wrote the original software.
15// If you use this software in a product, an acknowledgment
16// in the product documentation would be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such,
19// and must not be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source distribution.
22//
24
25#pragma once
26
28// Headers
31
32
33namespace sf
34{
35class String;
36
41namespace Keyboard
42{
51enum class Key
52{
53 Unknown = -1,
54 A = 0,
55 B,
56 C,
57 D,
58 E,
59 F,
60 G,
61 H,
62 I,
63 J,
64 K,
65 L,
66 M,
67 N,
68 O,
69 P,
70 Q,
71 R,
72 S,
73 T,
74 U,
75 V,
76 W,
77 X,
78 Y,
79 Z,
80 Num0,
81 Num1,
82 Num2,
83 Num3,
84 Num4,
85 Num5,
86 Num6,
87 Num7,
88 Num8,
89 Num9,
90 Escape,
91 LControl,
92 LShift,
93 LAlt,
94 LSystem,
95 RControl,
96 RShift,
97 RAlt,
98 RSystem,
99 Menu,
100 LBracket,
101 RBracket,
102 Semicolon,
103 Comma,
104 Period,
105 Apostrophe,
106 Slash,
107 Backslash,
108 Grave,
109 Equal,
110 Hyphen,
111 Space,
112 Enter,
113 Backspace,
114 Tab,
115 PageUp,
116 PageDown,
117 End,
118 Home,
119 Insert,
120 Delete,
121 Add,
122 Subtract,
123 Multiply,
124 Divide,
125 Left,
126 Right,
127 Up,
128 Down,
129 Numpad0,
130 Numpad1,
131 Numpad2,
132 Numpad3,
133 Numpad4,
134 Numpad5,
135 Numpad6,
136 Numpad7,
137 Numpad8,
138 Numpad9,
139 F1,
140 F2,
141 F3,
142 F4,
143 F5,
144 F6,
145 F7,
146 F8,
147 F9,
148 F10,
149 F11,
150 F12,
151 F13,
152 F14,
153 F15,
154 Pause,
155};
156
161// NOLINTNEXTLINE(readability-identifier-naming)
162static constexpr unsigned int KeyCount{static_cast<unsigned int>(Key::Pause) + 1};
163
172enum class Scan
173{
174 Unknown = -1,
175 A = 0,
176 B,
177 C,
178 D,
179 E,
180 F,
181 G,
182 H,
183 I,
184 J,
185 K,
186 L,
187 M,
188 N,
189 O,
190 P,
191 Q,
192 R,
193 S,
194 T,
195 U,
196 V,
197 W,
198 X,
199 Y,
200 Z,
201 Num1,
202 Num2,
203 Num3,
204 Num4,
205 Num5,
206 Num6,
207 Num7,
208 Num8,
209 Num9,
210 Num0,
211 Enter,
212 Escape,
213 Backspace,
214 Tab,
215 Space,
216 Hyphen,
217 Equal,
218 LBracket,
219 RBracket,
220 // For US keyboards mapped to key 29 (Microsoft Keyboard Scan Code Specification)
221 // For Non-US keyboards mapped to key 42 (Microsoft Keyboard Scan Code Specification)
222 // Typical language mappings: Belg:£µ` FrCa:<>} Dan:*' Dutch:`´ Fren:µ* Ger:'# Ital:§ù LatAm:[}` Nor:*@ Span:ç} Swed:*' Swiss:$£} UK:~# Brazil:}]
223 Backslash,
224 Semicolon,
225 Apostrophe,
226 Grave,
227 Comma,
228 Period,
229 Slash,
230 F1,
231 F2,
232 F3,
233 F4,
234 F5,
235 F6,
236 F7,
237 F8,
238 F9,
239 F10,
240 F11,
241 F12,
242 F13,
243 F14,
244 F15,
245 F16,
246 F17,
247 F18,
248 F19,
249 F20,
250 F21,
251 F22,
252 F23,
253 F24,
254 CapsLock,
256 ScrollLock,
257 Pause,
258 Insert,
259 Home,
260 PageUp,
261 Delete,
262 End,
263 PageDown,
264 Right,
265 Left,
266 Down,
267 Up,
268 NumLock,
272 NumpadPlus,
276 Numpad1,
277 Numpad2,
278 Numpad3,
279 Numpad4,
280 Numpad5,
281 Numpad6,
282 Numpad7,
283 Numpad8,
284 Numpad9,
285 Numpad0,
286 // For US keyboards doesn't exist
287 // For Non-US keyboards mapped to key 45 (Microsoft Keyboard Scan Code Specification)
288 // Typical language mappings: Belg:<> FrCa:«°» Dan:<> Dutch:]|[ Fren:<> Ger:<|> Ital:<> LatAm:<> Nor:<> Span:<> Swed:<|> Swiss:<> UK:\| Brazil: \|.
291 Execute,
292 ModeChange,
293 Help,
294 Menu,
295 Select,
296 Redo,
297 Undo,
298 Cut,
299 Copy,
300 Paste,
301 VolumeMute,
302 VolumeUp,
303 VolumeDown,
305 MediaStop,
308 LControl,
309 LShift,
310 LAlt,
311 LSystem,
312 RControl,
313 RShift,
314 RAlt,
315 RSystem,
316 Back,
317 Forward,
318 Refresh,
319 Stop,
320 Search,
321 Favorites,
322 HomePage,
325 LaunchMail,
327};
328
330
335// NOLINTNEXTLINE(readability-identifier-naming)
336static constexpr unsigned int ScancodeCount{static_cast<unsigned int>(Scan::LaunchMediaSelect) + 1};
337
349[[nodiscard]] SFML_WINDOW_API bool isKeyPressed(Key key);
350
362[[nodiscard]] SFML_WINDOW_API bool isKeyPressed(Scancode code);
363
378
393
416
431} // namespace Keyboard
432
433} // namespace sf
434
435
#define SFML_WINDOW_API
Utility string class that automatically handles conversions between types and encodings.
Definition String.hpp:89
Key localize(Scancode code)
Localize a physical key to a logical one.
static constexpr unsigned int KeyCount
The total number of keyboard keys, ignoring Key::Unknown
Definition Keyboard.hpp:162
static constexpr unsigned int ScancodeCount
The total number of scancodes, ignoring Scan::Unknown
Definition Keyboard.hpp:336
Scancode delocalize(Key key)
Identify the physical key corresponding to a logical one.
String getDescription(Scancode code)
Provide a string representation for a given scancode.
void setVirtualKeyboardVisible(bool visible)
Show or hide the virtual keyboard.
Key
Key codes.
Definition Keyboard.hpp:52
@ Escape
The Escape key.
@ Num6
The 6 key.
@ RAlt
The right Alt key.
@ Down
Down arrow.
@ Divide
The / key.
@ Pause
The Pause key.
@ Numpad9
The numpad 9 key.
@ LBracket
The [ key.
@ Period
The . key.
@ Numpad0
The numpad 0 key.
@ Subtract
The - key (minus, usually from numpad)
@ F6
The F6 key.
@ F14
The F14 key.
@ RSystem
The right OS specific key: window (Windows and Linux), apple (macOS), ...
@ Slash
The / key.
@ F5
The F5 key.
@ Numpad7
The numpad 7 key.
@ F7
The F7 key.
@ F8
The F8 key.
@ Num7
The 7 key.
@ F3
The F3 key.
@ Numpad6
The numpad 6 key.
@ Numpad4
The numpad 4 key.
@ Comma
The , key.
@ Tab
The Tabulation key.
@ Numpad3
The numpad 3 key.
@ Numpad5
The numpad 5 key.
@ F11
The F11 key.
@ LShift
The left Shift key.
@ Hyphen
The - key (hyphen)
@ Num2
The 2 key.
@ Num5
The 5 key.
@ Num0
The 0 key.
@ End
The End key.
@ Unknown
Unhandled key.
@ F9
The F9 key.
@ Num8
The 8 key.
@ Numpad8
The numpad 8 key.
@ Home
The Home key.
@ RShift
The right Shift key.
@ Right
Right arrow.
@ Left
Left arrow.
@ F13
The F13 key.
@ Semicolon
The ; key.
@ PageUp
The Page up key.
@ LControl
The left Control key.
@ Num3
The 3 key.
@ Insert
The Insert key.
@ LAlt
The left Alt key.
@ RControl
The right Control key.
@ F10
The F10 key.
@ Menu
The Menu key.
@ Apostrophe
The ' key.
@ Num1
The 1 key.
@ RBracket
The ] key.
@ Numpad1
The numpad 1 key.
@ Backspace
The Backspace key.
@ Space
The Space key.
@ Num9
The 9 key.
@ Num4
The 4 key.
@ F1
The F1 key.
@ Multiply
The * key.
@ F15
The F15 key.
@ F4
The F4 key.
@ F12
The F12 key.
@ Add
The + key.
@ Grave
The ` key.
@ PageDown
The Page down key.
@ Enter
The Enter/Return keys.
@ Delete
The Delete key.
@ Equal
The = key.
@ Backslash
The \ key.
@ Numpad2
The numpad 2 key.
@ LSystem
The left OS specific key: window (Windows and Linux), apple (macOS), ...
@ F2
The F2 key.
bool isKeyPressed(Key key)
Check if a key is pressed.
Scan
Scancodes.
Definition Keyboard.hpp:173
@ LaunchMediaSelect
Keyboard Launch Media Select key.
@ Back
Keyboard Back key.
@ Stop
Keyboard Stop key.
@ Search
Keyboard Search key.
@ Undo
Keyboard Undo key.
@ MediaPreviousTrack
Keyboard Media Previous Track key.
@ LaunchMail
Keyboard Launch Mail key.
@ Paste
Keyboard Paste key.
@ NumpadMultiply
Keypad * key.
@ Execute
Keyboard Execute key.
@ NumpadEnter
Keypad Enter/Return key.
@ MediaStop
Keyboard Media Stop key.
@ MediaNextTrack
Keyboard Media Next Track key.
@ F16
Keyboard F16 key.
@ Redo
Keyboard Redo key.
@ Copy
Keyboard Copy key.
@ Refresh
Keyboard Refresh key.
@ Forward
Keyboard Forward key.
@ Help
Keyboard Help key.
@ LaunchApplication2
Keyboard Launch Application 2 key.
@ F21
Keyboard F21 key.
@ ScrollLock
Keyboard Scroll Lock key.
@ F22
Keyboard F22 key.
@ F18
Keyboard F18 key.
@ F23
Keyboard F23 key.
@ NumpadEqual
keypad = key
@ CapsLock
Keyboard Caps Lock key.
@ VolumeDown
Keyboard Volume Down key.
@ VolumeMute
Keyboard Volume Mute key.
@ NumpadDecimal
Keypad . and Delete key.
@ NumpadPlus
Keypad + key.
@ MediaPlayPause
Keyboard Media Play Pause key.
@ NumpadDivide
Keypad / key.
@ PrintScreen
Keyboard Print Screen key.
@ HomePage
Keyboard Home Page key.
@ NonUsBackslash
Keyboard Non-US \ and | key.
@ F19
Keyboard F19 key.
@ NumLock
Keypad Num Lock and Clear key.
@ LaunchApplication1
Keyboard Launch Application 1 key.
@ Favorites
Keyboard Favorites key.
@ Select
Keyboard Select key.
@ Application
Keyboard Application key.
@ ModeChange
Keyboard Mode Change key.
@ Cut
Keyboard Cut key.
@ F24
Keyboard F24 key.
@ VolumeUp
Keyboard Volume Up key.
@ NumpadMinus
Keypad - key.
@ F20
Keyboard F20 key.
@ F17
Keyboard F17 key.