|
@@ -366,9 +366,10 @@ KeyCode getCode(string_view name)
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
-KeyCode getCode(SDL_Keycode key, Uint16 mod, SDL_Scancode scancode, bool release)
|
|
|
+std::pair<KeyCode, KeyCode> getCodes(SDL_Keycode key, Uint16 mod, SDL_Scancode scancode, bool release)
|
|
|
{
|
|
|
KeyCode result;
|
|
|
+ KeyCode scan;
|
|
|
switch (key) {
|
|
|
case SDLK_BACKSPACE: result = K_BACKSPACE; break;
|
|
|
case SDLK_TAB: result = K_TAB; break;
|
|
@@ -533,6 +534,149 @@ KeyCode getCode(SDL_Keycode key, Uint16 mod, SDL_Scancode scancode, bool release
|
|
|
default: result = K_UNKNOWN; break;
|
|
|
}
|
|
|
|
|
|
+ switch (scancode) {
|
|
|
+ case SDL_SCANCODE_BACKSPACE: scan = K_BACKSPACE; break;
|
|
|
+ case SDL_SCANCODE_TAB: scan = K_TAB; break;
|
|
|
+ case SDL_SCANCODE_CLEAR: scan = K_CLEAR; break;
|
|
|
+ case SDL_SCANCODE_RETURN: scan = K_RETURN; break;
|
|
|
+ case SDL_SCANCODE_PAUSE: scan = K_PAUSE; break;
|
|
|
+ case SDL_SCANCODE_ESCAPE: scan = K_ESCAPE; break;
|
|
|
+ case SDL_SCANCODE_SPACE: scan = K_SPACE; break;
|
|
|
+ case SDL_SCANCODE_APOSTROPHE: scan = K_QUOTE; break;
|
|
|
+ case SDL_SCANCODE_COMMA: scan = K_COMMA; break;
|
|
|
+ case SDL_SCANCODE_MINUS: scan = K_MINUS; break;
|
|
|
+ case SDL_SCANCODE_PERIOD: scan = K_PERIOD; break;
|
|
|
+ case SDL_SCANCODE_SLASH: scan = K_SLASH; break;
|
|
|
+ case SDL_SCANCODE_0: scan = K_0; break;
|
|
|
+ case SDL_SCANCODE_1: scan = K_1; break;
|
|
|
+ case SDL_SCANCODE_2: scan = K_2; break;
|
|
|
+ case SDL_SCANCODE_3: scan = K_3; break;
|
|
|
+ case SDL_SCANCODE_4: scan = K_4; break;
|
|
|
+ case SDL_SCANCODE_5: scan = K_5; break;
|
|
|
+ case SDL_SCANCODE_6: scan = K_6; break;
|
|
|
+ case SDL_SCANCODE_7: scan = K_7; break;
|
|
|
+ case SDL_SCANCODE_8: scan = K_8; break;
|
|
|
+ case SDL_SCANCODE_9: scan = K_9; break;
|
|
|
+ case SDL_SCANCODE_SEMICOLON: scan = K_SEMICOLON; break;
|
|
|
+ case SDL_SCANCODE_EQUALS: scan = K_EQUALS; break;
|
|
|
+
|
|
|
+ case SDL_SCANCODE_LEFTBRACKET: scan = K_LEFTBRACKET; break;
|
|
|
+ case SDL_SCANCODE_BACKSLASH: scan = K_BACKSLASH; break;
|
|
|
+ case SDL_SCANCODE_RIGHTBRACKET: scan = K_RIGHTBRACKET; break;
|
|
|
+ case SDL_SCANCODE_GRAVE: scan = K_BACKQUOTE; break;
|
|
|
+ case SDL_SCANCODE_A: scan = K_A; break;
|
|
|
+ case SDL_SCANCODE_B: scan = K_B; break;
|
|
|
+ case SDL_SCANCODE_C: scan = K_C; break;
|
|
|
+ case SDL_SCANCODE_D: scan = K_D; break;
|
|
|
+ case SDL_SCANCODE_E: scan = K_E; break;
|
|
|
+ case SDL_SCANCODE_F: scan = K_F; break;
|
|
|
+ case SDL_SCANCODE_G: scan = K_G; break;
|
|
|
+ case SDL_SCANCODE_H: scan = K_H; break;
|
|
|
+ case SDL_SCANCODE_I: scan = K_I; break;
|
|
|
+ case SDL_SCANCODE_J: scan = K_J; break;
|
|
|
+ case SDL_SCANCODE_K: scan = K_K; break;
|
|
|
+ case SDL_SCANCODE_L: scan = K_L; break;
|
|
|
+ case SDL_SCANCODE_M: scan = K_M; break;
|
|
|
+ case SDL_SCANCODE_N: scan = K_N; break;
|
|
|
+ case SDL_SCANCODE_O: scan = K_O; break;
|
|
|
+ case SDL_SCANCODE_P: scan = K_P; break;
|
|
|
+ case SDL_SCANCODE_Q: scan = K_Q; break;
|
|
|
+ case SDL_SCANCODE_R: scan = K_R; break;
|
|
|
+ case SDL_SCANCODE_S: scan = K_S; break;
|
|
|
+ case SDL_SCANCODE_T: scan = K_T; break;
|
|
|
+ case SDL_SCANCODE_U: scan = K_U; break;
|
|
|
+ case SDL_SCANCODE_V: scan = K_V; break;
|
|
|
+ case SDL_SCANCODE_W: scan = K_W; break;
|
|
|
+ case SDL_SCANCODE_X: scan = K_X; break;
|
|
|
+ case SDL_SCANCODE_Y: scan = K_Y; break;
|
|
|
+ case SDL_SCANCODE_Z: scan = K_Z; break;
|
|
|
+ case SDL_SCANCODE_DELETE: scan = K_DELETE; break;
|
|
|
+
|
|
|
+ // Numeric keypad
|
|
|
+ case SDL_SCANCODE_KP_0: scan = K_KP0; break;
|
|
|
+ case SDL_SCANCODE_KP_1: scan = K_KP1; break;
|
|
|
+ case SDL_SCANCODE_KP_2: scan = K_KP2; break;
|
|
|
+ case SDL_SCANCODE_KP_3: scan = K_KP3; break;
|
|
|
+ case SDL_SCANCODE_KP_4: scan = K_KP4; break;
|
|
|
+ case SDL_SCANCODE_KP_5: scan = K_KP5; break;
|
|
|
+ case SDL_SCANCODE_KP_6: scan = K_KP6; break;
|
|
|
+ case SDL_SCANCODE_KP_7: scan = K_KP7; break;
|
|
|
+ case SDL_SCANCODE_KP_8: scan = K_KP8; break;
|
|
|
+ case SDL_SCANCODE_KP_9: scan = K_KP9; break;
|
|
|
+ case SDL_SCANCODE_KP_PERIOD: scan = K_KP_PERIOD; break;
|
|
|
+ case SDL_SCANCODE_KP_DIVIDE: scan = K_KP_DIVIDE; break;
|
|
|
+ case SDL_SCANCODE_KP_MULTIPLY: scan = K_KP_MULTIPLY; break;
|
|
|
+ case SDL_SCANCODE_KP_MINUS: scan = K_KP_MINUS; break;
|
|
|
+ case SDL_SCANCODE_KP_PLUS: scan = K_KP_PLUS; break;
|
|
|
+ case SDL_SCANCODE_KP_ENTER: scan = K_KP_ENTER; break;
|
|
|
+ case SDL_SCANCODE_KP_EQUALS: scan = K_KP_EQUALS; break;
|
|
|
+
|
|
|
+ // Arrows + Home/End pad
|
|
|
+ case SDL_SCANCODE_UP: scan = K_UP; break;
|
|
|
+ case SDL_SCANCODE_DOWN: scan = K_DOWN; break;
|
|
|
+ case SDL_SCANCODE_RIGHT: scan = K_RIGHT; break;
|
|
|
+ case SDL_SCANCODE_LEFT: scan = K_LEFT; break;
|
|
|
+ case SDL_SCANCODE_INSERT: scan = K_INSERT; break;
|
|
|
+ case SDL_SCANCODE_HOME: scan = K_HOME; break;
|
|
|
+ case SDL_SCANCODE_END: scan = K_END; break;
|
|
|
+ case SDL_SCANCODE_PAGEUP: scan = K_PAGEUP; break;
|
|
|
+ case SDL_SCANCODE_PAGEDOWN: scan = K_PAGEDOWN; break;
|
|
|
+
|
|
|
+ // Function keys
|
|
|
+ case SDL_SCANCODE_F1: scan = K_F1; break;
|
|
|
+ case SDL_SCANCODE_F2: scan = K_F2; break;
|
|
|
+ case SDL_SCANCODE_F3: scan = K_F3; break;
|
|
|
+ case SDL_SCANCODE_F4: scan = K_F4; break;
|
|
|
+ case SDL_SCANCODE_F5: scan = K_F5; break;
|
|
|
+ case SDL_SCANCODE_F6: scan = K_F6; break;
|
|
|
+ case SDL_SCANCODE_F7: scan = K_F7; break;
|
|
|
+ case SDL_SCANCODE_F8: scan = K_F8; break;
|
|
|
+ case SDL_SCANCODE_F9: scan = K_F9; break;
|
|
|
+ case SDL_SCANCODE_F10: scan = K_F10; break;
|
|
|
+ case SDL_SCANCODE_F11: scan = K_F11; break;
|
|
|
+ case SDL_SCANCODE_F12: scan = K_F12; break;
|
|
|
+ case SDL_SCANCODE_F13: scan = K_F13; break;
|
|
|
+ case SDL_SCANCODE_F14: scan = K_F14; break;
|
|
|
+ case SDL_SCANCODE_F15: scan = K_F15; break;
|
|
|
+ case SDL_SCANCODE_F16: scan = K_F16; break;
|
|
|
+ case SDL_SCANCODE_F17: scan = K_F17; break;
|
|
|
+ case SDL_SCANCODE_F18: scan = K_F18; break;
|
|
|
+ case SDL_SCANCODE_F19: scan = K_F19; break;
|
|
|
+ case SDL_SCANCODE_F20: scan = K_F20; break;
|
|
|
+ case SDL_SCANCODE_F21: scan = K_F21; break;
|
|
|
+ case SDL_SCANCODE_F22: scan = K_F22; break;
|
|
|
+ case SDL_SCANCODE_F23: scan = K_F23; break;
|
|
|
+ case SDL_SCANCODE_F24: scan = K_F24; break;
|
|
|
+
|
|
|
+ // Key state modifier keys
|
|
|
+ case SDL_SCANCODE_NUMLOCKCLEAR: scan = K_NUMLOCK; break;
|
|
|
+ case SDL_SCANCODE_CAPSLOCK: scan = K_CAPSLOCK; break;
|
|
|
+ case SDL_SCANCODE_SCROLLLOCK: scan = K_SCROLLLOCK; break;
|
|
|
+ case SDL_SCANCODE_RSHIFT: scan = K_RSHIFT; break;
|
|
|
+ case SDL_SCANCODE_LSHIFT: scan = K_LSHIFT; break;
|
|
|
+ case SDL_SCANCODE_RCTRL: scan = K_RCTRL; break;
|
|
|
+ case SDL_SCANCODE_LCTRL: scan = K_LCTRL; break;
|
|
|
+ case SDL_SCANCODE_RALT: scan = K_RALT; break;
|
|
|
+ case SDL_SCANCODE_LALT: scan = K_LALT; break;
|
|
|
+ case SDL_SCANCODE_LGUI: scan = K_LSUPER; break; // Left "Windows" key
|
|
|
+ case SDL_SCANCODE_RGUI: scan = K_RSUPER; break; // Right "Windows" key
|
|
|
+ case SDL_SCANCODE_MODE: scan = K_MODE; break; // "Alt Gr" key
|
|
|
+
|
|
|
+ // Miscellaneous function keys
|
|
|
+ case SDL_SCANCODE_HELP: scan = K_HELP; break;
|
|
|
+ case SDL_SCANCODE_PRINTSCREEN: scan = K_PRINT; break;
|
|
|
+ case SDL_SCANCODE_SYSREQ: scan = K_SYSREQ; break;
|
|
|
+ case SDL_SCANCODE_APPLICATION: scan = K_MENU; break;
|
|
|
+ case SDL_SCANCODE_MENU: scan = K_MENU; break;
|
|
|
+ case SDL_SCANCODE_POWER: scan = K_POWER; break; // Power Macintosh power key
|
|
|
+ case SDL_SCANCODE_UNDO: scan = K_UNDO; break;
|
|
|
+
|
|
|
+ // Application Control keys
|
|
|
+ case SDL_SCANCODE_AC_BACK: scan = K_BACK; break;
|
|
|
+
|
|
|
+ default: scan = K_UNKNOWN; break;
|
|
|
+ }
|
|
|
+
|
|
|
// Handle keys that don't have a key code but do have a scan code.
|
|
|
if (result == K_UNKNOWN) {
|
|
|
// Assume it is a Japanese keyboard and check
|
|
@@ -560,30 +704,40 @@ KeyCode getCode(SDL_Keycode key, Uint16 mod, SDL_Scancode scancode, bool release
|
|
|
result = K_RALT;
|
|
|
default:
|
|
|
break; // nothing, silence compiler warning
|
|
|
+ // TODO: Maybe better to default to the scancode?
|
|
|
+ // Just so unknown keys do something.
|
|
|
+ //result = scan;
|
|
|
+ //break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// Apply modifiers.
|
|
|
if (mod & KMOD_CTRL) {
|
|
|
result = static_cast<KeyCode>(result | KM_CTRL);
|
|
|
+ scan = static_cast<KeyCode>(scan | KM_CTRL);
|
|
|
}
|
|
|
if (mod & KMOD_SHIFT) {
|
|
|
result = static_cast<KeyCode>(result | KM_SHIFT);
|
|
|
+ scan = static_cast<KeyCode>(scan | KM_SHIFT);
|
|
|
}
|
|
|
if (mod & KMOD_ALT) {
|
|
|
result = static_cast<KeyCode>(result | KM_ALT);
|
|
|
+ scan = static_cast<KeyCode>(scan | KM_ALT);
|
|
|
}
|
|
|
if (mod & KMOD_GUI) {
|
|
|
result = static_cast<KeyCode>(result | KM_META);
|
|
|
+ scan = static_cast<KeyCode>(scan | KM_META);
|
|
|
}
|
|
|
if (mod & KMOD_MODE) {
|
|
|
result = static_cast<KeyCode>(result | KM_MODE);
|
|
|
+ scan = static_cast<KeyCode>(scan | KM_MODE);
|
|
|
}
|
|
|
|
|
|
if (release) {
|
|
|
result = static_cast<KeyCode>(result | KD_RELEASE);
|
|
|
+ scan = static_cast<KeyCode>(scan | KD_RELEASE);
|
|
|
}
|
|
|
- return result;
|
|
|
+ return {result, scan};
|
|
|
}
|
|
|
|
|
|
string getName(KeyCode keyCode)
|