ReXGlue SDK
Loading...
Searching...
No Matches
input_keys.h
Go to the documentation of this file.
1
19
20#pragma once
21
22#include <cstdint>
23#include <string>
24#include <string_view>
25#include <vector>
26
27#include <rex/bit.h>
28#include <rex/platform.h>
29#include <rex/result.h>
30#include <rex/types.h>
31
32namespace rex {
33
35enum class VirtualKey : u16 {
36 kNone,
37
38 kLButton = 0x01,
39 kRButton = 0x02,
40 kCancel = 0x03,
41 kMButton = 0x04,
42
43 kXButton1 = 0x05,
44 kXButton2 = 0x06,
45
46 kBack = 0x08,
47 kTab = 0x09,
48
49 kClear = 0x0C,
50 kReturn = 0x0D,
51 kWheelUp = 0x0E,
52 kWheelDown = 0x0F,
53
54 kShift = 0x10,
55 kControl = 0x11,
56 kMenu = 0x12,
57 kPause = 0x13,
58 kCapital = 0x14,
59
60 kKana = 0x15,
61 kHangeul = 0x15,
62 kHangul = 0x15,
63 kIMEOn = 0x16,
64 kJunja = 0x17,
65 kFinal = 0x18,
66 kHanja = 0x19,
67 kKanji = 0x19,
68 kIMEOff = 0x1A,
69
70 kEscape = 0x1B,
71
72 kConvert = 0x1C,
73 kNonConvert = 0x1D,
74 kAccept = 0x1E,
75 kModeChange = 0x1F,
76
77 kSpace = 0x20,
78 kPrior = 0x21,
79 kNext = 0x22,
80 kEnd = 0x23,
81 kHome = 0x24,
82 kLeft = 0x25,
83 kUp = 0x26,
84 kRight = 0x27,
85 kDown = 0x28,
86 kSelect = 0x29,
87 kPrint = 0x2A,
88 kExecute = 0x2B,
89 kSnapshot = 0x2C,
90 kInsert = 0x2D,
91 kDelete = 0x2E,
92 kHelp = 0x2F,
93
96 k0 = 0x30,
97 k1 = 0x31,
98 k2 = 0x32,
99 k3 = 0x33,
100 k4 = 0x34,
101 k5 = 0x35,
102 k6 = 0x36,
103 k7 = 0x37,
104 k8 = 0x38,
105 k9 = 0x39,
107
110 kA = 0x41,
111 kB = 0x42,
112 kC = 0x43,
113 kD = 0x44,
114 kE = 0x45,
115 kF = 0x46,
116 kG = 0x47,
117 kH = 0x48,
118 kI = 0x49,
119 kJ = 0x4A,
120 kK = 0x4B,
121 kL = 0x4C,
122 kM = 0x4D,
123 kN = 0x4E,
124 kO = 0x4F,
125 kP = 0x50,
126 kQ = 0x51,
127 kR = 0x52,
128 kS = 0x53,
129 kT = 0x54,
130 kU = 0x55,
131 kV = 0x56,
132 kW = 0x57,
133 kX = 0x58,
134 kY = 0x59,
135 kZ = 0x5A,
137
138 kLWin = 0x5B,
139 kRWin = 0x5C,
140 kApps = 0x5D,
141
142 kSleep = 0x5F,
143
144 kNumpad0 = 0x60,
145 kNumpad1 = 0x61,
146 kNumpad2 = 0x62,
147 kNumpad3 = 0x63,
148 kNumpad4 = 0x64,
149 kNumpad5 = 0x65,
150 kNumpad6 = 0x66,
151 kNumpad7 = 0x67,
152 kNumpad8 = 0x68,
153 kNumpad9 = 0x69,
154 kMultiply = 0x6A,
155 kAdd = 0x6B,
156 kSeparator = 0x6C,
157 kSubtract = 0x6D,
158 kDecimal = 0x6E,
159 kDivide = 0x6F,
160 kF1 = 0x70,
161 kF2 = 0x71,
162 kF3 = 0x72,
163 kF4 = 0x73,
164 kF5 = 0x74,
165 kF6 = 0x75,
166 kF7 = 0x76,
167 kF8 = 0x77,
168 kF9 = 0x78,
169 kF10 = 0x79,
170 kF11 = 0x7A,
171 kF12 = 0x7B,
172 kF13 = 0x7C,
173 kF14 = 0x7D,
174 kF15 = 0x7E,
175 kF16 = 0x7F,
176 kF17 = 0x80,
177 kF18 = 0x81,
178 kF19 = 0x82,
179 kF20 = 0x83,
180 kF21 = 0x84,
181 kF22 = 0x85,
182 kF23 = 0x86,
183 kF24 = 0x87,
184
187 kNavigationMenu = 0x89,
188 kNavigationUp = 0x8A,
189 kNavigationDown = 0x8B,
190 kNavigationLeft = 0x8C,
191 kNavigationRight = 0x8D,
192 kNavigationAccept = 0x8E,
193 kNavigationCancel = 0x8F,
194
195 kNumLock = 0x90,
196 kScroll = 0x91,
197
200
202 kOemFjJisho = 0x92,
205 kOemFjLOya = 0x95,
206 kOemFjROya = 0x96,
207
212 kLShift = 0xA0,
213 kRShift = 0xA1,
214 kLControl = 0xA2,
215 kRControl = 0xA3,
216 kLMenu = 0xA4,
217 kRMenu = 0xA5,
218
219 kBrowserBack = 0xA6,
220 kBrowserForward = 0xA7,
221 kBrowserRefresh = 0xA8,
222 kBrowserStop = 0xA9,
223 kBrowserSearch = 0xAA,
224 kBrowserFavorites = 0xAB,
225 kBrowserHome = 0xAC,
226
227 kVolumeMute = 0xAD,
228 kVolumeDown = 0xAE,
229 kVolumeUp = 0xAF,
230 kMediaNextTrack = 0xB0,
231 kMediaPrevTrack = 0xB1,
232 kMediaStop = 0xB2,
233 kMediaPlayPause = 0xB3,
234 kLaunchMail = 0xB4,
235 kLaunchMediaSelect = 0xB5,
236 kLaunchApp1 = 0xB6,
237 kLaunchApp2 = 0xB7,
238
239 kOem1 = 0xBA,
240 kOemPlus = 0xBB,
241 kOemComma = 0xBC,
242 kOemMinus = 0xBD,
243 kOemPeriod = 0xBE,
244 kOem2 = 0xBF,
245 kOem3 = 0xC0,
246
249 kXboxOneGamepadB = 0xC4,
250 kXboxOneGamepadX = 0xC5,
251 kXboxOneGamepadY = 0xC6,
252 kXboxOneGamepadRightShoulder = 0xC7,
253 kXboxOneGamepadLeftShoulder = 0xC8,
254 kXboxOneGamepadLeftTrigger = 0xC9,
255 kXboxOneGamepadRightTrigger = 0xCA,
256 kXboxOneGamepadDpadUp = 0xCB,
257 kXboxOneGamepadDpadDown = 0xCC,
258 kXboxOneGamepadDpadLeft = 0xCD,
259 kXboxOneGamepadDpadRight = 0xCE,
260 kXboxOneGamepadMenu = 0xCF,
261 kXboxOneGamepadView = 0xD0,
262 kXboxOneGamepadLeftThumbstickButton = 0xD1,
263 kXboxOneGamepadRightThumbstickButton = 0xD2,
264 kXboxOneGamepadLeftThumbstickUp = 0xD3,
265 kXboxOneGamepadLeftThumbstickDown = 0xD4,
266 kXboxOneGamepadLeftThumbstickRight = 0xD5,
267 kXboxOneGamepadLeftThumbstickLeft = 0xD6,
268 kXboxOneGamepadRightThumbstickUp = 0xD7,
269 kXboxOneGamepadRightThumbstickDown = 0xD8,
270 kXboxOneGamepadRightThumbstickRight = 0xD9,
271 kXboxOneGamepadRightThumbstickLeft = 0xDA,
272
273 kOem4 = 0xDB,
274 kOem5 = 0xDC,
275 kOem6 = 0xDD,
276 kOem7 = 0xDE,
277 kOem8 = 0xDF,
278
279 kOemAx = 0xE1,
280 kOem102 = 0xE2,
281 kIcoHelp = 0xE3,
282 kIco00 = 0xE4,
283
284 kProcessKey = 0xE5,
285
286 kIcoClear = 0xE6,
287
292 kPacket = 0xE7,
293
295 kOemReset = 0xE9,
296 kOemJump = 0xEA,
297 kOemPa1 = 0xEB,
298 kOemPa2 = 0xEC,
299 kOemPa3 = 0xED,
300 kOemWsCtrl = 0xEE,
301 kOemCuSel = 0xEF,
302 kOemAttn = 0xF0,
303 kOemFinish = 0xF1,
304 kOemCopy = 0xF2,
305 kOemAuto = 0xF3,
306 kOemEnlW = 0xF4,
307 kOemBackTab = 0xF5,
308
309 kAttn = 0xF6,
310 kCrSel = 0xF7,
311 kExSel = 0xF8,
312 kErEof = 0xF9,
313 kPlay = 0xFA,
314 kZoom = 0xFB,
315 kNoName = 0xFC,
316 kPa1 = 0xFD,
317 kOemClear = 0xFE,
318
320
321 kXInputPadA = 0x5800,
322 kXInputPadB = 0x5801,
323 kXInputPadX = 0x5802,
324 kXInputPadY = 0x5803,
325 kXInputPadRShoulder = 0x5804,
326 kXInputPadLShoulder = 0x5805,
327 kXInputPadLTrigger = 0x5806,
328 kXInputPadRTrigger = 0x5807,
329
330 kXInputPadDPadUp = 0x5810,
331 kXInputPadDPadDown = 0x5811,
332 kXInputPadDPadLeft = 0x5812,
333 kXInputPadDPadRight = 0x5813,
334 kXInputPadStart = 0x5814,
335 kXInputPadBack = 0x5815,
336 kXInputPadLThumbPress = 0x5816,
337 kXInputPadRThumbPress = 0x5817,
338
339 kXInputPadLThumbUp = 0x5820,
340 kXInputPadLThumbDown = 0x5821,
341 kXInputPadLThumbRight = 0x5822,
342 kXInputPadLThumbLeft = 0x5823,
343 kXInputPadLThumbUpLeft = 0x5824,
344 kXInputPadLThumbUpRight = 0x5825,
345 kXInputPadLThumbDownRight = 0x5826,
346 kXInputPadLThumbDownLeft = 0x5827,
347
348 kXInputPadRThumbUp = 0x5830,
349 kXInputPadRThumbDown = 0x5831,
350 kXInputPadRThumbRight = 0x5832,
351 kXInputPadRThumbLeft = 0x5833,
352 kXInputPadRThumbUpLeft = 0x5834,
353 kXInputPadRThumbUpRight = 0x5835,
354 kXInputPadRThumbDownRight = 0x5836,
355 kXInputPadRThumbDownLeft = 0x5837,
356};
357
364REX_API VirtualKey ParseVirtualKey(std::string_view name);
365
370
371enum class PointerMode : u8 {
372 kFree,
373 kHidden,
375};
376
377enum class MouseButton : u8 {
378 kLeft,
379 kRight,
380 kMiddle,
381 kX1,
382 kX2,
383 kNone,
384};
385
386enum class KeyModifiers : u8 {
387 kNone = 0,
388 kShift = 1,
389 kCtrl = 2,
390 kAlt = 4,
391};
392
395 f32 x = 0.0f;
397 f32 y = 0.0f;
403 bool has_position = false;
404};
405
408 f32 dx = 0.0f;
410 f32 dy = 0.0f;
411};
412
418 enum class Type : u8 {
419 kKeyDown,
420 kKeyUp,
421 kKeyChar,
422 kButtonDown,
423 kButtonUp,
424 kMotion,
425 kWheel,
426 kFocusGained,
427 kFocusLost,
428 kResize,
429 };
430
431 Type type = Type::kKeyDown;
435 KeyModifiers modifiers = KeyModifiers::kNone;
437 bool repeat = false;
439 u32 character = 0;
441 MouseButton button = MouseButton::kLeft;
443 f32 x = 0.0f;
445 f32 y = 0.0f;
447 f32 dx = 0.0f;
449 f32 dy = 0.0f;
451 f32 scroll_x = 0.0f;
453 f32 scroll_y = 0.0f;
455 u32 width = 0;
457 u32 height = 0;
459 bool handled = false;
460};
461
462template <>
463inline constexpr bool is_flags_enum<KeyModifiers> = true;
464
472
474enum class PadInput : u8 {
475 kDpadUp,
476 kDpadDown,
477 kDpadLeft,
478 kDpadRight,
479 kStart,
480 kBack,
481 kLeftStickPress,
482 kRightStickPress,
483 kA,
484 kB,
485 kX,
486 kY,
487 kLeftTrigger,
488 kRightTrigger,
489 kLeftShoulder,
490 kRightShoulder,
491 kLeftStickUp,
492 kLeftStickDown,
493 kLeftStickRight,
494 kLeftStickLeft,
495 kRightStickUp,
496 kRightStickDown,
497 kRightStickRight,
498 kRightStickLeft,
499};
500
501inline constexpr u8 kPadButtonCount = 24;
502
503enum class PadAxes : u8 {
504 kNone,
505 kLeft,
506 kRight,
507};
508
512 u16 code = 0;
514 KeyModifiers modifiers = KeyModifiers::kNone;
516 i8 sign = 0;
518 u8 axis_slot = 0;
519
521 constexpr bool operator==(const InputSource& other) const = default;
522};
523
529constexpr bool IsSameInput(const InputSource& left, const InputSource& right) {
530 return left.type == right.type && left.code == right.code && left.modifiers == right.modifiers &&
531 left.sign == right.sign;
532}
533
535REX_API std::string_view GetPadButtonName(PadInput button);
536
544[[nodiscard]] REX_API Result<InputSource> ParseInputSource(std::string_view text);
545
551REX_API std::string InputSourceToString(const InputSource& source);
552
554struct KeyChord {
558 KeyModifiers modifiers = KeyModifiers::kNone;
559
560 constexpr bool operator==(const KeyChord& other) const = default;
561};
562
571[[nodiscard]] REX_API Result<KeyChord> ParseKeyChord(std::string_view text);
572
579[[nodiscard]] REX_API Result<std::vector<KeyChord>> ParseKeyChordList(std::string_view text);
580
588
589} // namespace rex
Definition app.h:36
Result< InputSource > ParseInputSource(std::string_view text)
VirtualKey
Definition input_keys.h:35
@ kNavigationView
Definition input_keys.h:186
@ kIcoHelp
Definition input_keys.h:281
@ kOemFjJisho
Definition input_keys.h:202
@ kSubtract
Definition input_keys.h:157
@ kOemFjMasshou
Definition input_keys.h:203
@ kOemReset
Definition input_keys.h:295
@ kXboxOneGamepadA
Definition input_keys.h:248
@ kOem1
Definition input_keys.h:239
@ kNone
Definition input_keys.h:36
@ kPrior
Definition input_keys.h:78
@ kOemMinus
Definition input_keys.h:242
@ kMenu
Definition input_keys.h:56
@ kHanja
Definition input_keys.h:66
@ kXInputPadA
Definition input_keys.h:321
@ kOemFjROya
Definition input_keys.h:206
@ kKanji
Definition input_keys.h:67
@ kOem4
Definition input_keys.h:273
@ kMultiply
Definition input_keys.h:154
@ kCancel
Definition input_keys.h:40
@ kIcoClear
Definition input_keys.h:286
@ kOem102
Definition input_keys.h:280
@ kOemFjTouroku
Definition input_keys.h:204
@ kOem8
Definition input_keys.h:277
@ kOemFjLOya
Definition input_keys.h:205
@ kLShift
Definition input_keys.h:212
@ kApps
Definition input_keys.h:140
@ kOem3
Definition input_keys.h:245
@ kOem7
Definition input_keys.h:276
@ kOem6
Definition input_keys.h:275
@ kOemNecEqual
Definition input_keys.h:199
@ kPacket
Definition input_keys.h:292
@ kSnapshot
Definition input_keys.h:89
@ kOemClear
Definition input_keys.h:317
@ kOem2
Definition input_keys.h:244
@ kNoName
Definition input_keys.h:315
@ kOemAx
Definition input_keys.h:279
@ kHangeul
Definition input_keys.h:61
@ kXButton2
Definition input_keys.h:44
@ kShift
Definition input_keys.h:54
@ kAdd
Definition input_keys.h:155
@ kOem5
Definition input_keys.h:274
@ kOemPeriod
Definition input_keys.h:243
@ kOemComma
Definition input_keys.h:241
@ kKana
Definition input_keys.h:60
@ kOemEnlW
Definition input_keys.h:306
@ kNext
Definition input_keys.h:79
@ kDecimal
Definition input_keys.h:158
@ kSeparator
Definition input_keys.h:156
@ kIco00
Definition input_keys.h:282
@ kXButton1
Definition input_keys.h:43
@ kHangul
Definition input_keys.h:62
@ kModeChange
Definition input_keys.h:75
@ kOemPlus
Definition input_keys.h:240
@ kDivide
Definition input_keys.h:159
@ kCapital
Definition input_keys.h:58
@ kScroll
Definition input_keys.h:196
constexpr bool is_flags_enum
Definition bit.h:422
std::string VirtualKeyToString(VirtualKey key)
std::string_view GetPadButtonName(PadInput button)
MouseButton
Definition input_keys.h:377
Result< KeyChord > ParseKeyChord(std::string_view text)
std::string InputSourceToString(const InputSource &source)
PadInput
Definition input_keys.h:474
PointerMode
Definition input_keys.h:371
@ kLocked
Definition input_keys.h:374
InputSourceType
Definition input_keys.h:466
@ kMouseWheel
Definition input_keys.h:468
@ kKey
Definition input_keys.h:467
@ kPadButton
Definition input_keys.h:469
@ kPadAxes
Definition input_keys.h:470
constexpr bool IsSameInput(const InputSource &left, const InputSource &right)
Definition input_keys.h:529
std::expected< T, Error > Result
Definition result.h:98
Result< std::vector< KeyChord > > ParseKeyChordList(std::string_view text)
std::string KeyChordToString(KeyChord chord)
VirtualKey ParseVirtualKey(std::string_view name)
Platform flags, packing macros and export markers.
#define REX_API
Definition platform.h:177
Definition input_keys.h:417
f32 dx
Definition input_keys.h:447
f32 scroll_y
Definition input_keys.h:453
MouseButton button
Definition input_keys.h:441
Type
Definition input_keys.h:418
@ kKeyDown
Definition input_keys.h:419
f32 scroll_x
Definition input_keys.h:451
VirtualKey key
Definition input_keys.h:433
u32 character
Definition input_keys.h:439
bool repeat
Definition input_keys.h:437
f32 dy
Definition input_keys.h:449
u32 width
Definition input_keys.h:455
KeyModifiers modifiers
Definition input_keys.h:435
f32 x
Definition input_keys.h:443
f32 y
Definition input_keys.h:445
u32 height
Definition input_keys.h:457
bool handled
Definition input_keys.h:459
Definition input_keys.h:509
u16 code
Definition input_keys.h:512
u8 axis_slot
Definition input_keys.h:518
KeyModifiers modifiers
Definition input_keys.h:514
constexpr bool operator==(const InputSource &other) const =default
i8 sign
Definition input_keys.h:516
Definition input_keys.h:554
VirtualKey key
Definition input_keys.h:556
KeyModifiers modifiers
Definition input_keys.h:558
Definition input_keys.h:406
f32 dx
Definition input_keys.h:408
f32 dy
Definition input_keys.h:410
Definition input_keys.h:393
f32 x
Definition input_keys.h:395
bool has_position
Definition input_keys.h:403
u32 window_height
Definition input_keys.h:401
u32 window_width
Definition input_keys.h:399
f32 y
Definition input_keys.h:397
Integer types, byte order wrappers and size literals.