Skip to content

Commit 6269f66

Browse files
committed
KeyCode mapping for runtime patch support: Added helper function to map codes from our InputKey enum to their "virtual key" equivalent
1 parent 0c22e4f commit 6269f66

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

src/game_runtime_patches.h

+105
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ namespace RuntimePatches {
196196

197197
namespace VirtualKeys {
198198
constexpr Input::Keys::InputKey VirtualKeyToInputKey(uint32_t key_id);
199+
200+
constexpr uint32_t InputKeyToVirtualKey(Input::Keys::InputKey input_key);
199201
}
200202
}
201203

@@ -303,4 +305,107 @@ constexpr Input::Keys::InputKey RuntimePatches::VirtualKeys::VirtualKeyToInputKe
303305
}
304306
}
305307

308+
constexpr uint32_t RuntimePatches::VirtualKeys::InputKeyToVirtualKey(Input::Keys::InputKey input_key) {
309+
switch (input_key) {
310+
#if defined(USE_MOUSE) && defined(SUPPORT_MOUSE)
311+
case Input::Keys::MOUSE_LEFT: return 0x1;
312+
case Input::Keys::MOUSE_RIGHT: return 0x2;
313+
case Input::Keys::MOUSE_MIDDLE: return 0x4;
314+
case Input::Keys::MOUSE_XBUTTON1: return 0x5;
315+
case Input::Keys::MOUSE_XBUTTON2: return 0x6;
316+
#endif
317+
case Input::Keys::BACKSPACE: return 0x8;
318+
case Input::Keys::TAB: return 0x9;
319+
case Input::Keys::RETURN: return 0xD;
320+
case Input::Keys::SHIFT: return 0x10;
321+
case Input::Keys::CTRL: return 0x11;
322+
case Input::Keys::ALT: return 0x12;
323+
case Input::Keys::PAUSE: return 0x13;
324+
case Input::Keys::CAPS_LOCK: return 0x14;
325+
case Input::Keys::ESCAPE: return 0x1B;
326+
case Input::Keys::SPACE: return 0x20;
327+
case Input::Keys::PGUP: return 0x21;
328+
case Input::Keys::PGDN: return 0x22;
329+
case Input::Keys::ENDS: return 0x23;
330+
case Input::Keys::HOME: return 0x24;
331+
case Input::Keys::LEFT: return 0x25;
332+
case Input::Keys::UP: return 0x26;
333+
case Input::Keys::RIGHT: return 0x27;
334+
case Input::Keys::DOWN: return 0x28;
335+
case Input::Keys::INSERT: return 0x2D;
336+
case Input::Keys::DEL: return 0x2E;
337+
case Input::Keys::N0: return 0x30;
338+
case Input::Keys::N1: return 0x31;
339+
case Input::Keys::N2: return 0x32;
340+
case Input::Keys::N3: return 0x33;
341+
case Input::Keys::N4: return 0x34;
342+
case Input::Keys::N5: return 0x35;
343+
case Input::Keys::N6: return 0x36;
344+
case Input::Keys::N7: return 0x37;
345+
case Input::Keys::N8: return 0x38;
346+
case Input::Keys::N9: return 0x39;
347+
case Input::Keys::A: return 0x41;
348+
case Input::Keys::B: return 0x42;
349+
case Input::Keys::C: return 0x43;
350+
case Input::Keys::D: return 0x44;
351+
case Input::Keys::E: return 0x45;
352+
case Input::Keys::F: return 0x46;
353+
case Input::Keys::G: return 0x47;
354+
case Input::Keys::H: return 0x48;
355+
case Input::Keys::I: return 0x49;
356+
case Input::Keys::J: return 0x4A;
357+
case Input::Keys::K: return 0x4B;
358+
case Input::Keys::L: return 0x4C;
359+
case Input::Keys::M: return 0x4D;
360+
case Input::Keys::N: return 0x4E;
361+
case Input::Keys::O: return 0x4F;
362+
case Input::Keys::P: return 0x50;
363+
case Input::Keys::Q: return 0x51;
364+
case Input::Keys::R: return 0x52;
365+
case Input::Keys::S: return 0x53;
366+
case Input::Keys::T: return 0x54;
367+
case Input::Keys::U: return 0x55;
368+
case Input::Keys::V: return 0x56;
369+
case Input::Keys::W: return 0x57;
370+
case Input::Keys::X: return 0x58;
371+
case Input::Keys::Y: return 0x59;
372+
case Input::Keys::Z: return 0x5A;
373+
case Input::Keys::KP0: return 0x60;
374+
case Input::Keys::KP1: return 0x61;
375+
case Input::Keys::KP2: return 0x62;
376+
case Input::Keys::KP3: return 0x63;
377+
case Input::Keys::KP4: return 0x64;
378+
case Input::Keys::KP5: return 0x65;
379+
case Input::Keys::KP6: return 0x66;
380+
case Input::Keys::KP7: return 0x67;
381+
case Input::Keys::KP8: return 0x68;
382+
case Input::Keys::KP9: return 0x69;
383+
case Input::Keys::KP_MULTIPLY: return 0x6A;
384+
case Input::Keys::KP_ADD: return 0x6B;
385+
case Input::Keys::KP_SUBTRACT: return 0x6D;
386+
case Input::Keys::KP_PERIOD: return 0x6E;
387+
case Input::Keys::KP_DIVIDE: return 0x6F;
388+
case Input::Keys::F1: return 0x70;
389+
case Input::Keys::F2: return 0x71;
390+
case Input::Keys::F3: return 0x72;
391+
case Input::Keys::F4: return 0x73;
392+
case Input::Keys::F5: return 0x74;
393+
case Input::Keys::F6: return 0x75;
394+
case Input::Keys::F7: return 0x76;
395+
case Input::Keys::F8: return 0x77;
396+
case Input::Keys::F9: return 0x78;
397+
case Input::Keys::F10: return 0x79;
398+
case Input::Keys::F11: return 0x7A;
399+
case Input::Keys::F12: return 0x7B;
400+
case Input::Keys::NUM_LOCK: return 0x90;
401+
case Input::Keys::SCROLL_LOCK: return 0x91;
402+
case Input::Keys::LSHIFT: return 0xA0;
403+
case Input::Keys::RSHIFT: return 0xA1;
404+
case Input::Keys::LCTRL: return 0xA2;
405+
case Input::Keys::RCTRL: return 0xA3;
406+
407+
default: return 0;
408+
}
409+
}
410+
306411
#endif

0 commit comments

Comments
 (0)