Documentation of SFML 2.6.2

Loading...
Searching...
No Matches
Keyboard.hpp
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2023 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#ifndef SFML_KEYBOARD_HPP
26#define SFML_KEYBOARD_HPP
27
29// Headers
31#include <SFML/Window/Export.hpp>
32
33
34namespace sf
35{
36class String;
37
42class SFML_WINDOW_API Keyboard
43{
44public:
45
171
180 struct Scan
181 {
182 // TODO: replace with enum class in SFML 3.
183 // Clang warns us rightfully that Scancode names shadow Key names.
184 // A safer solution would be to use a C++11 scoped enumeration (enum class),
185 // but it is not possible in SFML 2 which uses C++03.
186 // For now, we just ignore those warnings.
187 #if defined(__clang__)
188 #pragma clang diagnostic push
189 #pragma clang diagnostic ignored "-Wshadow"
190 #endif
191
193 {
194 Unknown = -1,
195 A = 0,
240 // For US keyboards mapped to key 29 (Microsoft Keyboard Scan Code Specification)
241 // For Non-US keyboards mapped to key 42 (Microsoft Keyboard Scan Code Specification)
242 // Typical language mappings: Belg:£µ` FrCa:<>} Dan:*' Dutch:`´ Fren:µ* Ger:'# Ital:§ù LatAm:[}` Nor:*@ Span:ç} Swed:*' Swiss:$£} UK:~# Brazil:}]
306 // For US keyboards doesn't exist
307 // For Non-US keyboards mapped to key 45 (Microsoft Keyboard Scan Code Specification)
308 // Typical language mappings: Belg:<> FrCa:«°» Dan:<> Dutch:]|[ Fren:<> Ger:<|> Ital:<> LatAm:<> Nor:<> Span:<> Swed:<|> Swiss:<> UK:\| Brazil: \|.
347
348 ScancodeCount
349 };
350
351 #if defined(__clang__)
352 #pragma clang diagnostic pop
353 #endif
354 };
355
356 typedef Scan::Scancode Scancode;
357
366 static bool isKeyPressed(Key key);
367
376 static bool isKeyPressed(Scancode code);
377
391 static Key localize(Scancode code);
392
407
428
442 static void setVirtualKeyboardVisible(bool visible);
443};
444
445} // namespace sf
446
447
448#endif // SFML_KEYBOARD_HPP
449
450
Give access to the real-time state of the keyboard.
Definition Keyboard.hpp:43
static Key localize(Scancode code)
Localize a physical key to a logical one.
static bool isKeyPressed(Key key)
Check if a key is pressed.
static bool isKeyPressed(Scancode code)
Check if a key is pressed.
static String getDescription(Scancode code)
Provide a string representation for a given scancode.
Key
Key codes.
Definition Keyboard.hpp:55
@ LAlt
The left Alt key.
Definition Keyboard.hpp:96
@ X
The X key.
Definition Keyboard.hpp:80
@ F5
The F5 key.
Definition Keyboard.hpp:146
@ Numpad1
The numpad 1 key.
Definition Keyboard.hpp:133
@ F7
The F7 key.
Definition Keyboard.hpp:148
@ C
The C key.
Definition Keyboard.hpp:59
@ E
The E key.
Definition Keyboard.hpp:61
@ Multiply
The * key.
Definition Keyboard.hpp:126
@ Add
The + key.
Definition Keyboard.hpp:124
@ T
The T key.
Definition Keyboard.hpp:76
@ Num5
The 5 key.
Definition Keyboard.hpp:88
@ F3
The F3 key.
Definition Keyboard.hpp:144
@ Tab
The Tabulation key.
Definition Keyboard.hpp:117
@ PageDown
The Page down key.
Definition Keyboard.hpp:119
@ RAlt
The right Alt key.
Definition Keyboard.hpp:100
@ W
The W key.
Definition Keyboard.hpp:79
@ K
The K key.
Definition Keyboard.hpp:67
@ Numpad8
The numpad 8 key.
Definition Keyboard.hpp:140
@ LShift
The left Shift key.
Definition Keyboard.hpp:95
@ RControl
The right Control key.
Definition Keyboard.hpp:98
@ Q
The Q key.
Definition Keyboard.hpp:73
@ Right
Right arrow.
Definition Keyboard.hpp:129
@ Num2
The 2 key.
Definition Keyboard.hpp:85
@ Grave
The ` key.
Definition Keyboard.hpp:111
@ Down
Down arrow.
Definition Keyboard.hpp:131
@ Numpad9
The numpad 9 key.
Definition Keyboard.hpp:141
@ F9
The F9 key.
Definition Keyboard.hpp:150
@ Numpad7
The numpad 7 key.
Definition Keyboard.hpp:139
@ End
The End key.
Definition Keyboard.hpp:120
@ Menu
The Menu key.
Definition Keyboard.hpp:102
@ Z
The Z key.
Definition Keyboard.hpp:82
@ Num1
The 1 key.
Definition Keyboard.hpp:84
@ RBracket
The ] key.
Definition Keyboard.hpp:104
@ Enter
The Enter/Return keys.
Definition Keyboard.hpp:115
@ Hyphen
The - key (hyphen)
Definition Keyboard.hpp:113
@ RShift
The right Shift key.
Definition Keyboard.hpp:99
@ Y
The Y key.
Definition Keyboard.hpp:81
@ L
The L key.
Definition Keyboard.hpp:68
@ Num4
The 4 key.
Definition Keyboard.hpp:87
@ Insert
The Insert key.
Definition Keyboard.hpp:122
@ Escape
The Escape key.
Definition Keyboard.hpp:93
@ Numpad4
The numpad 4 key.
Definition Keyboard.hpp:136
@ Subtract
The - key (minus, usually from numpad)
Definition Keyboard.hpp:125
@ F2
The F2 key.
Definition Keyboard.hpp:143
@ Space
The Space key.
Definition Keyboard.hpp:114
@ F4
The F4 key.
Definition Keyboard.hpp:145
@ LSystem
The left OS specific key: window (Windows and Linux), apple (macOS), ...
Definition Keyboard.hpp:97
@ Slash
The / key.
Definition Keyboard.hpp:109
@ O
The O key.
Definition Keyboard.hpp:71
@ Apostrophe
The ' key.
Definition Keyboard.hpp:108
@ F15
The F15 key.
Definition Keyboard.hpp:156
@ Numpad2
The numpad 2 key.
Definition Keyboard.hpp:134
@ Numpad5
The numpad 5 key.
Definition Keyboard.hpp:137
@ Num7
The 7 key.
Definition Keyboard.hpp:90
@ KeyCount
Keep last – the total number of keyboard keys.
Definition Keyboard.hpp:159
@ J
The J key.
Definition Keyboard.hpp:66
@ Pause
The Pause key.
Definition Keyboard.hpp:157
@ M
The M key.
Definition Keyboard.hpp:69
@ F14
The F14 key.
Definition Keyboard.hpp:155
@ Num9
The 9 key.
Definition Keyboard.hpp:92
@ F13
The F13 key.
Definition Keyboard.hpp:154
@ PageUp
The Page up key.
Definition Keyboard.hpp:118
@ Backspace
The Backspace key.
Definition Keyboard.hpp:116
@ P
The P key.
Definition Keyboard.hpp:72
@ Numpad6
The numpad 6 key.
Definition Keyboard.hpp:138
@ G
The G key.
Definition Keyboard.hpp:63
@ U
The U key.
Definition Keyboard.hpp:77
@ Semicolon
The ; key.
Definition Keyboard.hpp:105
@ Numpad3
The numpad 3 key.
Definition Keyboard.hpp:135
@ N
The N key.
Definition Keyboard.hpp:70
@ Delete
The Delete key.
Definition Keyboard.hpp:123
@ Comma
The , key.
Definition Keyboard.hpp:106
@ F
The F key.
Definition Keyboard.hpp:62
@ I
The I key.
Definition Keyboard.hpp:65
@ RSystem
The right OS specific key: window (Windows and Linux), apple (macOS), ...
Definition Keyboard.hpp:101
@ Left
Left arrow.
Definition Keyboard.hpp:128
@ Up
Up arrow.
Definition Keyboard.hpp:130
@ Period
The . key.
Definition Keyboard.hpp:107
@ F6
The F6 key.
Definition Keyboard.hpp:147
@ S
The S key.
Definition Keyboard.hpp:75
@ B
The B key.
Definition Keyboard.hpp:58
@ LControl
The left Control key.
Definition Keyboard.hpp:94
@ Num8
The 8 key.
Definition Keyboard.hpp:91
@ Backslash
The \ key.
Definition Keyboard.hpp:110
@ R
The R key.
Definition Keyboard.hpp:74
@ F8
The F8 key.
Definition Keyboard.hpp:149
@ H
The H key.
Definition Keyboard.hpp:64
@ Equal
The = key.
Definition Keyboard.hpp:112
@ F1
The F1 key.
Definition Keyboard.hpp:142
@ D
The D key.
Definition Keyboard.hpp:60
@ F10
The F10 key.
Definition Keyboard.hpp:151
@ V
The V key.
Definition Keyboard.hpp:78
@ Num3
The 3 key.
Definition Keyboard.hpp:86
@ Num0
The 0 key.
Definition Keyboard.hpp:83
@ Numpad0
The numpad 0 key.
Definition Keyboard.hpp:132
@ Home
The Home key.
Definition Keyboard.hpp:121
@ Num6
The 6 key.
Definition Keyboard.hpp:89
@ F11
The F11 key.
Definition Keyboard.hpp:152
@ F12
The F12 key.
Definition Keyboard.hpp:153
@ Divide
The / key.
Definition Keyboard.hpp:127
@ LBracket
The [ key.
Definition Keyboard.hpp:103
static void setVirtualKeyboardVisible(bool visible)
Show or hide the virtual keyboard.
static Scancode delocalize(Key key)
Identify the physical key corresponding to a logical one.
Utility string class that automatically handles conversions between types and encodings.
Definition String.hpp:46
@ Backslash
Keyboard \ and | key OR various keys for Non-US keyboards.
Definition Keyboard.hpp:243
@ Comma
Keyboard , and < key.
Definition Keyboard.hpp:247
@ Stop
Keyboard Stop key.
Definition Keyboard.hpp:339
@ Right
Keyboard Right Arrow key.
Definition Keyboard.hpp:284
@ F24
Keyboard F24 key.
Definition Keyboard.hpp:273
@ F20
Keyboard F20 key.
Definition Keyboard.hpp:269
@ MediaNextTrack
Keyboard Media Next Track key.
Definition Keyboard.hpp:326
@ P
Keyboard p and P key.
Definition Keyboard.hpp:210
@ PageUp
Keyboard Page Up key.
Definition Keyboard.hpp:280
@ Execute
Keyboard Execute key.
Definition Keyboard.hpp:311
@ Num4
Keyboard 4 and $ key.
Definition Keyboard.hpp:224
@ Num2
Keyboard 2 and @ key.
Definition Keyboard.hpp:222
@ Numpad3
Keypad 3 and Page Down key.
Definition Keyboard.hpp:298
@ Down
Keyboard Down Arrow key.
Definition Keyboard.hpp:286
@ Search
Keyboard Search key.
Definition Keyboard.hpp:340
@ F16
Keyboard F16 key.
Definition Keyboard.hpp:265
@ K
Keyboard k and K key.
Definition Keyboard.hpp:205
@ LaunchMediaSelect
Keyboard Launch Media Select key.
Definition Keyboard.hpp:346
@ Refresh
Keyboard Refresh key.
Definition Keyboard.hpp:338
@ G
Keyboard g and G key.
Definition Keyboard.hpp:201
@ Left
Keyboard Left Arrow key.
Definition Keyboard.hpp:285
@ Numpad4
Keypad 4 and Left Arrow key.
Definition Keyboard.hpp:299
@ W
Keyboard w and W key.
Definition Keyboard.hpp:217
@ Z
Keyboard z and Z key.
Definition Keyboard.hpp:220
@ RAlt
Keyboard Right Alt key.
Definition Keyboard.hpp:334
@ F
Keyboard f and F key.
Definition Keyboard.hpp:200
@ Delete
Keyboard Delete Forward key.
Definition Keyboard.hpp:281
@ Select
Keyboard Select key.
Definition Keyboard.hpp:315
@ Num3
Keyboard 3 and # key.
Definition Keyboard.hpp:223
@ Numpad9
Keypad 9 and Page Up key.
Definition Keyboard.hpp:304
@ Space
Keyboard Space key.
Definition Keyboard.hpp:235
@ PageDown
Keyboard Page Down key.
Definition Keyboard.hpp:283
@ VolumeMute
Keyboard Volume Mute key.
Definition Keyboard.hpp:321
@ F6
Keyboard F6 key.
Definition Keyboard.hpp:255
@ S
Keyboard s and S key.
Definition Keyboard.hpp:213
@ Numpad7
Keypad 7 and Home key.
Definition Keyboard.hpp:302
@ LBracket
Keyboard [ and { key.
Definition Keyboard.hpp:238
@ F2
Keyboard F2 key.
Definition Keyboard.hpp:251
@ H
Keyboard h and H key.
Definition Keyboard.hpp:202
@ Pause
Keyboard Pause key.
Definition Keyboard.hpp:277
@ MediaPlayPause
Keyboard Media Play Pause key.
Definition Keyboard.hpp:324
@ NonUsBackslash
Keyboard Non-US \ and | key.
Definition Keyboard.hpp:309
@ Help
Keyboard Help key.
Definition Keyboard.hpp:313
@ F5
Keyboard F5 key.
Definition Keyboard.hpp:254
@ F11
Keyboard F11 key.
Definition Keyboard.hpp:260
@ F19
Keyboard F19 key.
Definition Keyboard.hpp:268
@ F22
Keyboard F22 key.
Definition Keyboard.hpp:271
@ Numpad2
Keypad 2 and Down Arrow key.
Definition Keyboard.hpp:297
@ T
Keyboard t and T key.
Definition Keyboard.hpp:214
@ Numpad6
Keypad 6 and Right Arrow key.
Definition Keyboard.hpp:301
@ Numpad0
Keypad 0 and Insert key.
Definition Keyboard.hpp:305
@ B
Keyboard b and B key.
Definition Keyboard.hpp:196
@ Application
Keyboard Application key.
Definition Keyboard.hpp:310
@ M
Keyboard m and M key.
Definition Keyboard.hpp:207
@ RBracket
Keyboard ] and } key.
Definition Keyboard.hpp:239
@ NumpadEqual
keypad = key
Definition Keyboard.hpp:293
@ Slash
Keyboard / and ? key.
Definition Keyboard.hpp:249
@ F7
Keyboard F7 key.
Definition Keyboard.hpp:256
@ LSystem
Keyboard Left System key.
Definition Keyboard.hpp:331
@ F1
Keyboard F1 key.
Definition Keyboard.hpp:250
@ End
Keyboard End key.
Definition Keyboard.hpp:282
@ Semicolon
Keyboard ; and : key.
Definition Keyboard.hpp:244
@ NumpadDecimal
Keypad . and Delete key.
Definition Keyboard.hpp:295
@ RSystem
Keyboard Right System key.
Definition Keyboard.hpp:335
@ Y
Keyboard y and Y key.
Definition Keyboard.hpp:219
@ Backspace
Keyboard Backspace key.
Definition Keyboard.hpp:233
@ CapsLock
Keyboard Caps Lock key.
Definition Keyboard.hpp:274
@ MediaStop
Keyboard Media Stop key.
Definition Keyboard.hpp:325
@ Up
Keyboard Up Arrow key.
Definition Keyboard.hpp:287
@ Equal
Keyboard = and +.
Definition Keyboard.hpp:237
@ Num6
Keyboard 6 and ^ key.
Definition Keyboard.hpp:226
@ N
Keyboard n and N key.
Definition Keyboard.hpp:208
@ Numpad8
Keypad 8 and Up Arrow key.
Definition Keyboard.hpp:303
@ Copy
Keyboard Copy key.
Definition Keyboard.hpp:319
@ LaunchApplication2
Keyboard Launch Application 2 key.
Definition Keyboard.hpp:344
@ Grave
Keyboard ` and ~ key.
Definition Keyboard.hpp:246
@ RShift
Keyboard Right Shift key.
Definition Keyboard.hpp:333
@ F14
Keyboard F14 key.
Definition Keyboard.hpp:263
@ PrintScreen
Keyboard Print Screen key.
Definition Keyboard.hpp:275
@ Insert
Keyboard Insert key.
Definition Keyboard.hpp:278
@ Numpad5
Keypad 5 key.
Definition Keyboard.hpp:300
@ D
Keyboard d and D key.
Definition Keyboard.hpp:198
@ HomePage
Keyboard Home Page key.
Definition Keyboard.hpp:342
@ LShift
Keyboard Left Shift key.
Definition Keyboard.hpp:329
@ LAlt
Keyboard Left Alt key.
Definition Keyboard.hpp:330
@ F12
Keyboard F12 key.
Definition Keyboard.hpp:261
@ VolumeDown
Keyboard Volume Down key.
Definition Keyboard.hpp:323
@ F17
Keyboard F17 key.
Definition Keyboard.hpp:266
@ Tab
Keyboard Tab key.
Definition Keyboard.hpp:234
@ VolumeUp
Keyboard Volume Up key.
Definition Keyboard.hpp:322
@ LControl
Keyboard Left Control key.
Definition Keyboard.hpp:328
@ Num7
Keyboard 7 and & key.
Definition Keyboard.hpp:227
@ J
Keyboard j and J key.
Definition Keyboard.hpp:204
@ O
Keyboard o and O key.
Definition Keyboard.hpp:209
@ Paste
Keyboard Paste key.
Definition Keyboard.hpp:320
@ L
Keyboard l and L key.
Definition Keyboard.hpp:206
@ RControl
Keyboard Right Control key.
Definition Keyboard.hpp:332
@ LaunchMail
Keyboard Launch Mail key.
Definition Keyboard.hpp:345
@ NumpadPlus
Keypad + key.
Definition Keyboard.hpp:292
@ ScrollLock
Keyboard Scroll Lock key.
Definition Keyboard.hpp:276
@ NumpadMultiply
Keypad * key.
Definition Keyboard.hpp:290
@ Num5
Keyboard 5 and % key.
Definition Keyboard.hpp:225
@ Numpad1
Keypad 1 and End key.
Definition Keyboard.hpp:296
@ LaunchApplication1
Keyboard Launch Application 1 key.
Definition Keyboard.hpp:343
@ MediaPreviousTrack
Keyboard Media Previous Track key.
Definition Keyboard.hpp:327
@ Apostrophe
Keyboard ' and " key.
Definition Keyboard.hpp:245
@ NumpadDivide
Keypad / key.
Definition Keyboard.hpp:289
@ F23
Keyboard F23 key.
Definition Keyboard.hpp:272
@ Undo
Keyboard Undo key.
Definition Keyboard.hpp:317
@ Escape
Keyboard Escape key.
Definition Keyboard.hpp:232
@ F15
Keyboard F15 key.
Definition Keyboard.hpp:264
@ V
Keyboard v and V key.
Definition Keyboard.hpp:216
@ I
Keyboard i and I key.
Definition Keyboard.hpp:203
@ NumLock
Keypad Num Lock and Clear key.
Definition Keyboard.hpp:288
@ C
Keyboard c and C key.
Definition Keyboard.hpp:197
@ Favorites
Keyboard Favorites key.
Definition Keyboard.hpp:341
@ NumpadEnter
Keypad Enter/Return key.
Definition Keyboard.hpp:294
@ Menu
Keyboard Menu key.
Definition Keyboard.hpp:314
@ Redo
Keyboard Redo key.
Definition Keyboard.hpp:316
@ F21
Keyboard F21 key.
Definition Keyboard.hpp:270
@ Enter
Keyboard Enter/Return key.
Definition Keyboard.hpp:231
@ Forward
Keyboard Forward key.
Definition Keyboard.hpp:337
@ Num0
Keyboard 0 and ) key.
Definition Keyboard.hpp:230
@ ModeChange
Keyboard Mode Change key.
Definition Keyboard.hpp:312
@ Num1
Keyboard 1 and ! key.
Definition Keyboard.hpp:221
@ E
Keyboard e and E key.
Definition Keyboard.hpp:199
@ Period
Keyboard . and > key.
Definition Keyboard.hpp:248
@ F9
Keyboard F9 key.
Definition Keyboard.hpp:258
@ F8
Keyboard F8 key.
Definition Keyboard.hpp:257
@ NumpadMinus
Keypad - key.
Definition Keyboard.hpp:291
@ F4
Keyboard F4 key.
Definition Keyboard.hpp:253
@ F18
Keyboard F18 key.
Definition Keyboard.hpp:267
@ Back
Keyboard Back key.
Definition Keyboard.hpp:336
@ Home
Keyboard Home key.
Definition Keyboard.hpp:279
@ Hyphen
Keyboard - and _ key.
Definition Keyboard.hpp:236
@ U
Keyboard u and U key.
Definition Keyboard.hpp:215
@ F10
Keyboard F10 key.
Definition Keyboard.hpp:259
@ Num8
Keyboard 8 and * key.
Definition Keyboard.hpp:228
@ Num9
Keyboard 9 and ) key.
Definition Keyboard.hpp:229
@ R
Keyboard r and R key.
Definition Keyboard.hpp:212
@ F3
Keyboard F3 key.
Definition Keyboard.hpp:252
@ F13
Keyboard F13 key.
Definition Keyboard.hpp:262
@ X
Keyboard x and X key.
Definition Keyboard.hpp:218
@ Cut
Keyboard Cut key.
Definition Keyboard.hpp:318
@ Q
Keyboard q and Q key.
Definition Keyboard.hpp:211