Sparkle 0.0.1
Loading...
Searching...
No Matches
spk_keyboard.hpp
1#pragma once
2
3#include <array>
4#include <ostream>
5#include <string>
6
7#include "type/spk_input_state.hpp"
8
9namespace spk
10{
15 struct Keyboard
16 {
20 enum Key
21 {
22 Backspace = 8,
23 Tab = 9,
24 Clear = 12,
25 Return = 13,
26 Shift = 16,
27 Control = 17,
28 Alt = 18,
29 Pause = 19,
30 Capslock = 20,
31 Escape = 27,
32 Convert = 28,
33 Non_convert = 29,
34 Accept = 30,
35 Mode_change = 31,
36 Space = 32,
37 Prior = 33,
38 Next = 34,
39 End = 35,
40 Home = 36,
41 LeftArrow = 37,
42 UpArrow = 38,
43 RightArrow = 39,
44 DownArrow = 40,
45 Select = 41,
46 Print = 42,
47 Execute = 43,
48 Snapshot = 44,
49 Insert = 45,
50 Delete = 46,
51 Help = 47,
52 Key0 = 48,
53 Key1 = 49,
54 Key2 = 50,
55 Key3 = 51,
56 Key4 = 52,
57 Key5 = 53,
58 Key6 = 54,
59 Key7 = 55,
60 Key8 = 56,
61 Key9 = 57,
62 A = 65,
63 B = 66,
64 C = 67,
65 D = 68,
66 E = 69,
67 F = 70,
68 G = 71,
69 H = 72,
70 I = 73,
71 J = 74,
72 K = 75,
73 L = 76,
74 M = 77,
75 N = 78,
76 O = 79,
77 P = 80,
78 Q = 81,
79 R = 82,
80 S = 83,
81 T = 84,
82 U = 85,
83 V = 86,
84 W = 87,
85 X = 88,
86 Y = 89,
87 Z = 90,
88 LeftWindows = 91,
89 RightWindows = 92,
90 App = 93,
91 Sleep = 95,
92 Numpad0 = 96,
93 Numpad1 = 97,
94 Numpad2 = 98,
95 Numpad3 = 99,
96 Numpad4 = 100,
97 Numpad5 = 101,
98 Numpad6 = 102,
99 Numpad7 = 103,
100 Numpad8 = 104,
101 Numpad9 = 105,
102 NumpadMultiply = 106,
103 NumpadPlus = 107,
104 NumpadSeparator = 108,
105 NumpadMinus = 109,
106 NumpadDecimal = 110,
107 NumpadDivide = 111,
108 F1 = 112,
109 F2 = 113,
110 F3 = 114,
111 F4 = 115,
112 F5 = 116,
113 F6 = 117,
114 F7 = 118,
115 F8 = 119,
116 F9 = 120,
117 F10 = 121,
118 F11 = 122,
119 F12 = 123,
120 F13 = 124,
121 F14 = 125,
122 F15 = 126,
123 F16 = 127,
124 F17 = 128,
125 F18 = 129,
126 F19 = 130,
127 F20 = 131,
128 F21 = 132,
129 F22 = 133,
130 F23 = 134,
131 F24 = 135,
132 NumLock = 144,
133 Scroll = 145,
134 LeftShift = 160,
135 RightShift = 161,
136 LeftControl = 162,
137 RightControl = 163,
138 LeftMenu = 164,
139 RightMenu = 165,
140 SemiColon = 186,
141 Plus = 187,
142 Comma = 188,
143 Minus = 189,
144 Period = 190,
145 QuestionMark = 191,
146 Tilde = 192,
147 LeftBracket = 219,
148 VerticalLine = 220,
149 RightBracket = 221,
150 Quote = 222,
151 Unknow = 223,
152 AngleBracket = 226,
153 Process = 229
154 };
155
158 static inline const size_t NbKey = 255;
159
163 std::array<InputState, NbKey> keys;
167 wchar_t glyph;
168
169 Keyboard()
170 {
171 for (auto &state : keys)
172 {
173 state = InputState::Up;
174 }
175 }
176
182 InputState &operator[](const Key p_key)
183 {
184 return keys[static_cast<size_t>(p_key)];
185 }
186
192 const InputState &operator[](const Key p_key) const
193 {
194 return keys[static_cast<size_t>(p_key)];
195 }
196 };
197
198 std::string toString(const Keyboard::Key &p_key);
199 std::wstring toWstring(const Keyboard::Key &p_key);
200
201 std::ostream &operator<<(std::ostream &p_stream, const Keyboard::Key &p_key);
202 std::wostream &operator<<(std::wostream &p_stream, const Keyboard::Key &p_key);
203
204}
static const size_t NbKey
Number of key codes defined in the enumeration.
Definition spk_keyboard.hpp:158
const InputState & operator[](const Key p_key) const
Accesses the state of a key.
Definition spk_keyboard.hpp:192
Key
Enumeration of supported keyboard keys using platform scan codes.
Definition spk_keyboard.hpp:21
wchar_t glyph
Last received glyph (for text input).
Definition spk_keyboard.hpp:167
InputState & operator[](const Key p_key)
Accesses the state of a key.
Definition spk_keyboard.hpp:182
std::array< InputState, NbKey > keys
State of each key, indexed by Key code.
Definition spk_keyboard.hpp:163