Nameless Engine
Loading...
Searching...
No Matches
KeyboardKey.hpp
1#pragma once
2
3// Custom.
4#include "window/GLFW.hpp"
5
6namespace ne {
11 public:
12 KeyboardModifiers() = delete;
13
19 explicit KeyboardModifiers(int iModifiers) { this->iModifiers = iModifiers; }
20
26 bool isShiftPressed() const { return iModifiers & GLFW_MOD_SHIFT; }
27
33 bool isControlPressed() const { return iModifiers & GLFW_MOD_CONTROL; }
34
40 bool isAltPressed() const { return iModifiers & GLFW_MOD_ALT; }
41
47 bool isSuperPressed() const { return iModifiers & GLFW_MOD_SUPER; }
48
54 bool isCapsLockPressed() const { return iModifiers & GLFW_MOD_CAPS_LOCK; }
55
61 bool isNumLockPressed() const { return iModifiers & GLFW_MOD_NUM_LOCK; }
62
63 private:
66 };
67
71 enum class KeyboardAction { PRESSED = GLFW_PRESS, RELEASED = GLFW_RELEASE };
72
77 enum class KeyboardKey {
78 KEY_UNKNOWN = GLFW_KEY_UNKNOWN,
79 KEY_SPACE = GLFW_KEY_SPACE,
80 KEY_APOSTROPHE = GLFW_KEY_APOSTROPHE,
81 KEY_COMMA = GLFW_KEY_COMMA,
82 KEY_MINUS = GLFW_KEY_MINUS,
83 KEY_PERIOD = GLFW_KEY_PERIOD,
84 KEY_SLASH = GLFW_KEY_SLASH,
85 KEY_0 = GLFW_KEY_0,
86 KEY_1 = GLFW_KEY_1,
87 KEY_2 = GLFW_KEY_2,
88 KEY_3 = GLFW_KEY_3,
89 KEY_4 = GLFW_KEY_4,
90 KEY_5 = GLFW_KEY_5,
91 KEY_6 = GLFW_KEY_6,
92 KEY_7 = GLFW_KEY_7,
93 KEY_8 = GLFW_KEY_8,
94 KEY_9 = GLFW_KEY_9,
95 KEY_SEMICOLON = GLFW_KEY_SEMICOLON,
96 KEY_EQUAL = GLFW_KEY_EQUAL,
97 KEY_A = GLFW_KEY_A,
98 KEY_B = GLFW_KEY_B,
99 KEY_C = GLFW_KEY_C,
100 KEY_D = GLFW_KEY_D,
101 KEY_E = GLFW_KEY_E,
102 KEY_F = GLFW_KEY_F,
103 KEY_G = GLFW_KEY_G,
104 KEY_H = GLFW_KEY_H,
105 KEY_I = GLFW_KEY_I,
106 KEY_J = GLFW_KEY_J,
107 KEY_K = GLFW_KEY_K,
108 KEY_L = GLFW_KEY_L,
109 KEY_M = GLFW_KEY_M,
110 KEY_N = GLFW_KEY_N,
111 KEY_O = GLFW_KEY_O,
112 KEY_P = GLFW_KEY_P,
113 KEY_Q = GLFW_KEY_Q,
114 KEY_R = GLFW_KEY_R,
115 KEY_S = GLFW_KEY_S,
116 KEY_T = GLFW_KEY_T,
117 KEY_U = GLFW_KEY_U,
118 KEY_V = GLFW_KEY_V,
119 KEY_W = GLFW_KEY_W,
120 KEY_X = GLFW_KEY_X,
121 KEY_Y = GLFW_KEY_Y,
122 KEY_Z = GLFW_KEY_Z,
123 KEY_LEFT_BRACKET = GLFW_KEY_LEFT_BRACKET,
124 KEY_BACKSLASH = GLFW_KEY_BACKSLASH,
125 KEY_RIGHT_BRACKET = GLFW_KEY_RIGHT_BRACKET,
126 KEY_GRAVE_ACCENT = GLFW_KEY_GRAVE_ACCENT,
127 KEY_WORLD_1 = GLFW_KEY_WORLD_1,
128 KEY_WORLD_2 = GLFW_KEY_WORLD_2,
129 KEY_ESCAPE = GLFW_KEY_ESCAPE,
130 KEY_ENTER = GLFW_KEY_ENTER,
131 KEY_TAB = GLFW_KEY_TAB,
132 KEY_BACKSPACE = GLFW_KEY_BACKSPACE,
133 KEY_INSERT = GLFW_KEY_INSERT,
134 KEY_DELETE = GLFW_KEY_DELETE,
135 KEY_RIGHT = GLFW_KEY_RIGHT,
136 KEY_LEFT = GLFW_KEY_LEFT,
137 KEY_DOWN = GLFW_KEY_DOWN,
138 KEY_UP = GLFW_KEY_UP,
139 KEY_PAGE_UP = GLFW_KEY_PAGE_UP,
140 KEY_PAGE_DOWN = GLFW_KEY_PAGE_DOWN,
141 KEY_HOME = GLFW_KEY_HOME,
142 KEY_END = GLFW_KEY_END,
143 KEY_CAPS_LOCK = GLFW_KEY_CAPS_LOCK,
144 KEY_SCROLL_LOCK = GLFW_KEY_SCROLL_LOCK,
145 KEY_NUM_LOCK = GLFW_KEY_NUM_LOCK,
146 KEY_PRINT_SCREEN = GLFW_KEY_PRINT_SCREEN,
147 KEY_PAUSE = GLFW_KEY_PAUSE,
148 KEY_F1 = GLFW_KEY_F1,
149 KEY_F2 = GLFW_KEY_F2,
150 KEY_F3 = GLFW_KEY_F3,
151 KEY_F4 = GLFW_KEY_F4,
152 KEY_F5 = GLFW_KEY_F5,
153 KEY_F6 = GLFW_KEY_F6,
154 KEY_F7 = GLFW_KEY_F7,
155 KEY_F8 = GLFW_KEY_F8,
156 KEY_F9 = GLFW_KEY_F9,
157 KEY_F10 = GLFW_KEY_F10,
158 KEY_F11 = GLFW_KEY_F11,
159 KEY_F12 = GLFW_KEY_F12,
160 KEY_F13 = GLFW_KEY_F13,
161 KEY_F14 = GLFW_KEY_F14,
162 KEY_F15 = GLFW_KEY_F15,
163 KEY_F16 = GLFW_KEY_F16,
164 KEY_F17 = GLFW_KEY_F17,
165 KEY_F18 = GLFW_KEY_F18,
166 KEY_F19 = GLFW_KEY_F19,
167 KEY_F20 = GLFW_KEY_F20,
168 KEY_F21 = GLFW_KEY_F21,
169 KEY_F22 = GLFW_KEY_F22,
170 KEY_F23 = GLFW_KEY_F23,
171 KEY_F24 = GLFW_KEY_F24,
172 KEY_F25 = GLFW_KEY_F25,
173 KEY_KP_0 = GLFW_KEY_KP_0,
174 KEY_KP_1 = GLFW_KEY_KP_1,
175 KEY_KP_2 = GLFW_KEY_KP_2,
176 KEY_KP_3 = GLFW_KEY_KP_3,
177 KEY_KP_4 = GLFW_KEY_KP_4,
178 KEY_KP_5 = GLFW_KEY_KP_5,
179 KEY_KP_6 = GLFW_KEY_KP_6,
180 KEY_KP_7 = GLFW_KEY_KP_7,
181 KEY_KP_8 = GLFW_KEY_KP_8,
182 KEY_KP_9 = GLFW_KEY_KP_9,
183 KEY_KP_DECIMAL = GLFW_KEY_KP_DECIMAL,
184 KEY_KP_DIVIDE = GLFW_KEY_KP_DIVIDE,
185 KEY_KP_MULTIPLY = GLFW_KEY_KP_MULTIPLY,
186 KEY_KP_SUBTRACT = GLFW_KEY_KP_SUBTRACT,
187 KEY_KP_ADD = GLFW_KEY_KP_ADD,
188 KEY_KP_ENTER = GLFW_KEY_KP_ENTER,
189 KEY_KP_EQUAL = GLFW_KEY_KP_EQUAL,
190 KEY_LEFT_SHIFT = GLFW_KEY_LEFT_SHIFT,
191 KEY_LEFT_CONTROL = GLFW_KEY_LEFT_CONTROL,
192 KEY_LEFT_ALT = GLFW_KEY_LEFT_ALT,
193 KEY_LEFT_SUPER = GLFW_KEY_LEFT_SUPER,
194 KEY_RIGHT_SHIFT = GLFW_KEY_RIGHT_SHIFT,
195 KEY_RIGHT_CONTROL = GLFW_KEY_RIGHT_CONTROL,
196 KEY_RIGHT_ALT = GLFW_KEY_RIGHT_ALT,
197 KEY_RIGHT_SUPER = GLFW_KEY_RIGHT_SUPER,
198 KEY_MENU = GLFW_KEY_MENU,
199 };
200
209 inline std::string getKeyName(KeyboardKey key) {
210 const auto pName = glfwGetKeyName(static_cast<int>(key), 0);
211 if (pName == nullptr) {
212 switch (key) { // translate some keys
213 case KeyboardKey::KEY_TAB:
214 return "Tab";
215 case KeyboardKey::KEY_CAPS_LOCK:
216 return "Caps Lock";
217 case KeyboardKey::KEY_LEFT_SHIFT:
218 return "Left Shift";
219 case KeyboardKey::KEY_RIGHT_SHIFT:
220 return "Right Shift";
221 case KeyboardKey::KEY_LEFT_CONTROL:
222 return "Left Ctrl";
223 case KeyboardKey::KEY_RIGHT_CONTROL:
224 return "Right Ctrl";
225 case KeyboardKey::KEY_LEFT_SUPER:
226 return "Left Super";
227 case KeyboardKey::KEY_RIGHT_SUPER:
228 return "Right Super";
229 case KeyboardKey::KEY_LEFT_ALT:
230 return "Left Alt";
231 case KeyboardKey::KEY_RIGHT_ALT:
232 return "Right Alt";
233 case KeyboardKey::KEY_BACKSPACE:
234 return "Backspace";
235 case KeyboardKey::KEY_ENTER:
236 return "Enter";
237 case KeyboardKey::KEY_UP:
238 return "Up";
239 case KeyboardKey::KEY_DOWN:
240 return "Down";
241 case KeyboardKey::KEY_LEFT:
242 return "Left";
243 case KeyboardKey::KEY_RIGHT:
244 return "Right";
245 case KeyboardKey::KEY_SPACE:
246 return "Space Bar";
247 case KeyboardKey::KEY_ESCAPE:
248 return "Escape";
249 case KeyboardKey::KEY_F1:
250 return "F1";
251 case KeyboardKey::KEY_F2:
252 return "F2";
253 case KeyboardKey::KEY_F3:
254 return "F3";
255 case KeyboardKey::KEY_F4:
256 return "F4";
257 case KeyboardKey::KEY_F5:
258 return "F5";
259 case KeyboardKey::KEY_F6:
260 return "F6";
261 case KeyboardKey::KEY_F7:
262 return "F7";
263 case KeyboardKey::KEY_F8:
264 return "F8";
265 case KeyboardKey::KEY_F9:
266 return "F9";
267 case KeyboardKey::KEY_F10:
268 return "F10";
269 case KeyboardKey::KEY_F11:
270 return "F11";
271 case KeyboardKey::KEY_F12:
272 return "F12";
273 case KeyboardKey::KEY_F13:
274 return "F13";
275 case KeyboardKey::KEY_F14:
276 return "F14";
277 case KeyboardKey::KEY_F15:
278 return "F15";
279 case KeyboardKey::KEY_F16:
280 return "F16";
281 case KeyboardKey::KEY_F17:
282 return "F17";
283 case KeyboardKey::KEY_F18:
284 return "F18";
285 case KeyboardKey::KEY_F19:
286 return "F19";
287 case KeyboardKey::KEY_F20:
288 return "F20";
289 case KeyboardKey::KEY_F21:
290 return "F21";
291 case KeyboardKey::KEY_F22:
292 return "F22";
293 case KeyboardKey::KEY_F23:
294 return "F23";
295 case KeyboardKey::KEY_F24:
296 return "F24";
297 case KeyboardKey::KEY_F25:
298 return "F25";
299 case KeyboardKey::KEY_PRINT_SCREEN:
300 return "Print Screen";
301 case KeyboardKey::KEY_INSERT:
302 return "Insert";
303 case KeyboardKey::KEY_DELETE:
304 return "Delete";
305 default:
306 return "?";
307 }
308 } else {
309 return pName;
310 }
311 }
312} // namespace ne
Definition: KeyboardKey.hpp:10
bool isNumLockPressed() const
Definition: KeyboardKey.hpp:61
bool isCapsLockPressed() const
Definition: KeyboardKey.hpp:54
bool isSuperPressed() const
Definition: KeyboardKey.hpp:47
bool isShiftPressed() const
Definition: KeyboardKey.hpp:26
int iModifiers
Definition: KeyboardKey.hpp:65
bool isAltPressed() const
Definition: KeyboardKey.hpp:40
bool isControlPressed() const
Definition: KeyboardKey.hpp:33
KeyboardModifiers(int iModifiers)
Definition: KeyboardKey.hpp:19