sdl2-compat: Updated for latest SDL3 changes as of c9cfa4688ebbce108604793f7673f9b81d0cb61a

From 5a52a79f6647c68dbe94df8c8733f4a54ab80682 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Fri, 21 Jun 2024 22:06:52 -0700
Subject: [PATCH] Updated for latest SDL3 changes as of
 c9cfa4688ebbce108604793f7673f9b81d0cb61a

---
 src/sdl2_compat.c          | 238 +++++++++++++++++++++-
 src/sdl2_compat.h          | 401 +++++++++++++++++++++++++++++++++++++
 src/sdl2_protos.h          |   8 +-
 src/sdl3_include_wrapper.h |  10 +
 src/sdl3_syms.h            |  12 +-
 5 files changed, 655 insertions(+), 14 deletions(-)

diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index 7b5aa1e..b3852ae 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -850,7 +850,7 @@ typedef struct SDL2_KeyboardEvent
     Uint8 repeat;
     Uint8 padding2;
     Uint8 padding3;
-    SDL_Keysym keysym;
+    SDL2_Keysym keysym;
 } SDL2_KeyboardEvent;
 
 #define SDL2_TEXTEDITINGEVENT_TEXT_SIZE (32)
@@ -1534,6 +1534,68 @@ static Uint8 SwapGamepadButton(Uint8 button)
     }
 }
 
+static SDL_Scancode SDL2ScancodeToSDL3Scancode(SDL2_Scancode scancode)
+{
+    if (scancode <= SDL2_SCANCODE_MODE) {
+        // They're the same
+        return (SDL_Scancode)scancode;
+    }
+
+    switch (scancode) {
+    case SDL2_SCANCODE_AUDIOFASTFORWARD:
+        return SDL_SCANCODE_MEDIA_FAST_FORWARD;
+    case SDL2_SCANCODE_AUDIOMUTE:
+        return SDL_SCANCODE_MUTE;
+    case SDL2_SCANCODE_AUDIONEXT:
+        return SDL_SCANCODE_MEDIA_NEXT_TRACK;
+    case SDL2_SCANCODE_AUDIOPLAY:
+        return SDL_SCANCODE_MEDIA_PLAY;
+    case SDL2_SCANCODE_AUDIOPREV:
+        return SDL_SCANCODE_MEDIA_PREVIOUS_TRACK;
+    case SDL2_SCANCODE_AUDIOREWIND:
+        return SDL_SCANCODE_MEDIA_REWIND;
+    case SDL2_SCANCODE_AUDIOSTOP:
+        return SDL_SCANCODE_MEDIA_STOP;
+    case SDL2_SCANCODE_EJECT:
+        return SDL_SCANCODE_MEDIA_EJECT;
+    case SDL2_SCANCODE_MEDIASELECT:
+        return SDL_SCANCODE_MEDIA_SELECT;
+    default:
+        return SDL_SCANCODE_UNKNOWN;
+    }
+}
+
+static SDL2_Scancode SDL3ScancodeToSDL2Scancode(SDL_Scancode scancode)
+{
+    if (scancode <= SDL_SCANCODE_MODE) {
+        // They're the same
+        return (SDL2_Scancode)scancode;
+    }
+
+    switch (scancode) {
+    case SDL_SCANCODE_MEDIA_FAST_FORWARD:
+        return SDL2_SCANCODE_AUDIOFASTFORWARD;
+    case SDL_SCANCODE_MUTE:
+        return SDL2_SCANCODE_AUDIOMUTE;
+    case SDL_SCANCODE_MEDIA_NEXT_TRACK:
+        return SDL2_SCANCODE_AUDIONEXT;
+    case SDL_SCANCODE_MEDIA_PLAY:
+        return SDL2_SCANCODE_AUDIOPLAY;
+    case SDL_SCANCODE_MEDIA_PREVIOUS_TRACK:
+        return SDL2_SCANCODE_AUDIOPREV;
+    case SDL_SCANCODE_MEDIA_REWIND:
+        return SDL2_SCANCODE_AUDIOREWIND;
+    case SDL_SCANCODE_MEDIA_STOP:
+        return SDL2_SCANCODE_AUDIOSTOP;
+    case SDL_SCANCODE_MEDIA_EJECT:
+        return SDL2_SCANCODE_EJECT;
+    case SDL_SCANCODE_MEDIA_SELECT:
+        return SDL2_SCANCODE_MEDIASELECT;
+    default:
+        return SDL2_SCANCODE_UNKNOWN;
+    }
+}
+
 /* (current) strategy for SDL_Events:
    in sdl12-compat, we built our own event queue, so when the SDL2 queue is pumped, we
    took the events we cared about and added them to the sdl12-compat queue, and otherwise
@@ -1574,9 +1636,11 @@ Event3to2(const SDL_Event *event3, SDL2_Event *event2)
     switch (event3->type) {
     case SDL_EVENT_KEY_DOWN:
     case SDL_EVENT_KEY_UP:
+        event2->key.keysym.scancode = SDL3ScancodeToSDL2Scancode(event3->key.scancode);
+        event2->key.keysym.sym = event3->key.key;
+        event2->key.keysym.mod = event3->key.mod;
         event2->key.state = event3->key.state;
         event2->key.repeat = event3->key.repeat;
-        event2->key.keysym = event3->key.keysym;
         break;
     case SDL_EVENT_TEXT_INPUT:
         SDL3_strlcpy(event2->text.text, event3->text.text, sizeof(event2->text.text));
@@ -1720,15 +1784,20 @@ Event2to3(const SDL2_Event *event2, SDL_Event *event3)
     case SDL_EVENT_TEXT_INPUT: {
         const size_t len = SDL3_strlen(event2->text.text) + 1;
         event3->text.text = (char *)SDL3_AllocateEventMemory(len);
-        SDL3_memcpy(event3->text.text, event3->text.text, len);
+        if (event3->text.text) {
+            SDL3_memcpy((char *)event3->text.text, event3->text.text, len);
+        }
         break;
     }
     case SDL_EVENT_KEY_DOWN:
     case SDL_EVENT_KEY_UP:
         event3->key.which = 0;
+        event3->key.scancode = SDL2ScancodeToSDL3Scancode(event2->key.keysym.scancode);
+        event3->key.key = event2->key.keysym.sym;
+        event3->key.mod = event2->key.keysym.mod;
+        event3->key.raw = 0;
         event3->key.state = event2->key.state;
         event3->key.repeat = event2->key.repeat;
-        event3->key.keysym = event2->key.keysym;
         break;
     #if 0 /* FIXME: Can this ever happen? */
     case SDL_EVENT_TEXT_EDITING: {
@@ -2037,6 +2106,167 @@ SDL_SetModState(SDL2_Keymod modstate)
     SDL3_SetModState((SDL_Keymod)modstate);
 }
 
+SDL_DECLSPEC SDL_Keycode SDLCALL
+SDL_GetKeyFromScancode(SDL2_Scancode scancode)
+{
+    if (((int)scancode) < SDL2_SCANCODE_UNKNOWN || scancode >= SDL2_NUM_SCANCODES) {
+        SDL3_InvalidParamError("scancode");
+        return 0;
+    }
+
+    if (scancode <= SDL2_SCANCODE_MODE) {
+        // They're the same
+        return SDL3_GetKeyFromScancode(SDL2ScancodeToSDL3Scancode(scancode), SDL_KMOD_NONE);
+    } else {
+        return SDL_SCANCODE_TO_KEYCODE(scancode);
+    }
+}
+
+SDL_DECLSPEC SDL2_Scancode SDLCALL
+SDL_GetScancodeFromKey(SDL_Keycode key)
+{
+    SDL_Keymod modstate = SDL_KMOD_NONE;
+    SDL_Scancode scancode = SDL3_GetScancodeFromKey(key, &modstate);
+    if (modstate != SDL_KMOD_NONE) {
+        return SDL2_SCANCODE_UNKNOWN;
+    }
+    return SDL3ScancodeToSDL2Scancode(scancode);
+}
+
+static const char *SDL2_scancode_names[] = {
+    /* 258 */ "AudioNext",
+    /* 259 */ "AudioPrev",
+    /* 260 */ "AudioStop",
+    /* 261 */ "AudioPlay",
+    /* 262 */ "AudioMute",
+    /* 263 */ "MediaSelect",
+    /* 264 */ "WWW",
+    /* 265 */ "Mail",
+    /* 266 */ "Calculator",
+    /* 267 */ "Computer",
+    /* 268 */ "AC Search",
+    /* 269 */ "AC Home",
+    /* 270 */ "AC Back",
+    /* 271 */ "AC Forward",
+    /* 272 */ "AC Stop",
+    /* 273 */ "AC Refresh",
+    /* 274 */ "AC Bookmarks",
+    /* 275 */ "BrightnessDown",
+    /* 276 */ "BrightnessUp",
+    /* 277 */ "DisplaySwitch",
+    /* 278 */ "KBDIllumToggle",
+    /* 279 */ "KBDIllumDown",
+    /* 280 */ "KBDIllumUp",
+    /* 281 */ "Eject",
+    /* 282 */ "Sleep",
+    /* 283 */ "App1",
+    /* 284 */ "App2",
+    /* 285 */ "AudioRewind",
+    /* 286 */ "AudioFastForward",
+    /* 287 */ "SoftLeft",
+    /* 288 */ "SoftRight",
+    /* 289 */ "Call",
+    /* 290 */ "EndCall",
+};
+
+SDL_DECLSPEC const char *SDLCALL
+SDL_GetScancodeName(SDL2_Scancode scancode)
+{
+    unsigned int i;
+
+    if (scancode <= SDL2_SCANCODE_MODE) {
+        // They're the same
+        return SDL3_GetScancodeName(SDL2ScancodeToSDL3Scancode(scancode));
+    }
+
+    i = (unsigned int)scancode - (SDL2_SCANCODE_MODE + 1);
+    if (i >= SDL_arraysize(SDL2_scancode_names)) {
+        SDL3_InvalidParamError("scancode");
+        return "";
+    }
+    return SDL2_scancode_names[i];
+}
+
+SDL_DECLSPEC SDL2_Scancode SDLCALL
+SDL_GetScancodeFromName(const char *name)
+{
+    int i;
+
+    if (!name || !*name) {
+        SDL3_InvalidParamError("name");
+        return SDL2_SCANCODE_UNKNOWN;
+    }
+
+    for (i = 0; i < SDL2_NUM_SCANCODES; ++i) {
+        if (SDL3_strcasecmp(name, SDL_GetScancodeName((SDL2_Scancode)i)) == 0) {
+            return (SDL2_Scancode)i;
+        }
+    }
+
+    SDL3_InvalidParamError("name");
+    return SDL2_SCANCODE_UNKNOWN;
+}
+
+SDL_DECLSPEC const char * SDLCALL
+SDL_GetKeyName(SDL_Keycode key)
+{
+    if (key & SDLK_SCANCODE_MASK) {
+        return SDL_GetScancodeName((SDL2_Scancode)(key & ~SDLK_SCANCODE_MASK));
+    }
+    return SDL3_GetKeyName(key);
+}
+
+SDL_DECLSPEC SDL_Keycode SDLCALL
+SDL_GetKeyFromName(const char *name)
+{
+    SDL_Keycode key;
+
+    /* Check input */
+    if (!name) {
+        return SDLK_UNKNOWN;
+    }
+
+    /* If it's a single UTF-8 character, then that's the keycode itself */
+    key = *(const unsigned char *)name;
+    if (key >= 0xF0) {
+        if (SDL_strlen(name) == 4) {
+            int i = 0;
+            key = (Uint16)(name[i] & 0x07) << 18;
+            key |= (Uint16)(name[++i] & 0x3F) << 12;
+            key |= (Uint16)(name[++i] & 0x3F) << 6;
+            key |= (Uint16)(name[++i] & 0x3F);
+            return key;
+        }
+        return SDLK_UNKNOWN;
+    } else if (key >= 0xE0) {
+        if (SDL_strlen(name) == 3) {
+            int i = 0;
+            key = (Uint16)(name[i] & 0x0F) << 12;
+            key |= (Uint16)(name[++i] & 0x3F) << 6;
+            key |= (Uint16)(name[++i] & 0x3F);
+            return key;
+        }
+        return SDLK_UNKNOWN;
+    } else if (key >= 0xC0) {
+        if (SDL_strlen(name) == 2) {
+            int i = 0;
+            key = (Uint16)(name[i] & 0x1F) << 6;
+            key |= (Uint16)(name[++i] & 0x3F);
+            return key;
+        }
+        return SDLK_UNKNOWN;
+    } else {
+        if (SDL_strlen(name) == 1) {
+            if (key >= 'A' && key <= 'Z') {
+                key += 32;
+            }
+            return key;
+        }
+
+        /* Get the scancode for this name, and the associated keycode */
+        return SDL_GetKeyFromScancode(SDL_GetScancodeFromName(name));
+    }
+}
 
 /* Several SDL3 video backends have had their names lower-cased, map to the SDL2 equivalent name. */
 static const char *ReplaceVideoBackendName(const char *name)
diff --git a/src/sdl2_compat.h b/src/sdl2_compat.h
index 67fd6c3..96ded28 100644
--- a/src/sdl2_compat.h
+++ b/src/sdl2_compat.h
@@ -111,6 +111,407 @@ typedef struct SDL2_DisplayMode SDL2_DisplayMode;
 
 typedef struct SDL2_hid_device_info SDL2_hid_device_info;
 
+typedef enum SDL2_Scancode
+{
+    SDL2_SCANCODE_UNKNOWN = 0,
+
+    /**
+     *  \name Usage page 0x07
+     *
+     *  These values are from usage page 0x07 (USB keyboard page).
+     */
+    /* @{ */
+
+    SDL2_SCANCODE_A = 4,
+    SDL2_SCANCODE_B = 5,
+    SDL2_SCANCODE_C = 6,
+    SDL2_SCANCODE_D = 7,
+    SDL2_SCANCODE_E = 8,
+    SDL2_SCANCODE_F = 9,
+    SDL2_SCANCODE_G = 10,
+    SDL2_SCANCODE_H = 11,
+    SDL2_SCANCODE_I = 12,
+    SDL2_SCANCODE_J = 13,
+    SDL2_SCANCODE_K = 14,
+    SDL2_SCANCODE_L = 15,
+    SDL2_SCANCODE_M = 16,
+    SDL2_SCANCODE_N = 17,
+    SDL2_SCANCODE_O = 18,
+    SDL2_SCANCODE_P = 19,
+    SDL2_SCANCODE_Q = 20,
+    SDL2_SCANCODE_R = 21,
+    SDL2_SCANCODE_S = 22,
+    SDL2_SCANCODE_T = 23,
+    SDL2_SCANCODE_U = 24,
+    SDL2_SCANCODE_V = 25,
+    SDL2_SCANCODE_W = 26,
+    SDL2_SCANCODE_X = 27,
+    SDL2_SCANCODE_Y = 28,
+    SDL2_SCANCODE_Z = 29,
+
+    SDL2_SCANCODE_1 = 30,
+    SDL2_SCANCODE_2 = 31,
+    SDL2_SCANCODE_3 = 32,
+    SDL2_SCANCODE_4 = 33,
+    SDL2_SCANCODE_5 = 34,
+    SDL2_SCANCODE_6 = 35,
+    SDL2_SCANCODE_7 = 36,
+    SDL2_SCANCODE_8 = 37,
+    SDL2_SCANCODE_9 = 38,
+    SDL2_SCANCODE_0 = 39,
+
+    SDL2_SCANCODE_RETURN = 40,
+    SDL2_SCANCODE_ESCAPE = 41,
+    SDL2_SCANCODE_BACKSPACE = 42,
+    SDL2_SCANCODE_TAB = 43,
+    SDL2_SCANCODE_SPACE = 44,
+
+    SDL2_SCANCODE_MINUS = 45,
+    SDL2_SCANCODE_EQUALS = 46,
+    SDL2_SCANCODE_LEFTBRACKET = 47,
+    SDL2_SCANCODE_RIGHTBRACKET = 48,
+    SDL2_SCANCODE_BACKSLASH = 49, /**< Located at the lower left of the return
+                                  *   key on ISO keyboards and at the right end
+                                  *   of the QWERTY row on ANSI keyboards.
+                                  *   Produces REVERSE SOLIDUS (backslash) and
+                                  *   VERTICAL LINE in a US layout, REVERSE
+                                  *   SOLIDUS and VERTICAL LINE in a UK Mac
+                                  *   layout, NUMBER SIGN and TILDE in a UK
+                                  *   Windows layout, DOLLAR SIGN and POUND SIGN
+                                  *   in a Swiss German layout, NUMBER SIGN and
+                                  *   APOSTROPHE in a German layout, GRAVE
+                                  *   ACCENT and POUND SIGN in a French Mac
+                                  *   layout, and ASTERISK and MICRO SIGN in a
+                                  *   French Windows layout.
+                                  */
+    SDL2_SCANCODE_NONUSHASH = 50, /**< ISO USB keyboards actually use this code
+                                  *   instead of 49 for the same key, but all
+                                  *   OSes I've seen treat the two codes
+                                  *   identically. So, as an implementor, unless
+                                  *   your keyboard generates both of those
+                                  *   codes and your OS treats them differently,
+                                  *   you should generate SDL2_SCANCODE_BACKSLASH
+                                  *   instead of this code. As a user, you
+                                  *   should not rely on this code because SDL
+                                  *   will never generate it with most (all?)
+                                  *   keyboards.
+                                  */
+    SDL2_SCANCODE_SEMICOLON = 51,
+    SDL2_SCANCODE_APOSTROPHE = 52,
+    SDL2_SCANCODE_GRAVE = 53, /**< Located in the top left corner (on both ANSI
+                              *   and ISO keyboards). Produces GRAVE ACCENT and
+                              *   TILDE in a US Windows layout and in US and UK
+                              *   Mac layouts on ANSI keyboards, GRAVE ACCENT
+                              *   and NOT SIGN in a UK Windows layout, SECTION
+                              *   SIGN and PLUS-MINUS SIGN in US and UK Mac
+                              *   layouts on ISO keyboards, SECTION SIGN and
+                              *   DEGREE SIGN in a Swiss German layout (Mac:
+                              *   only on ISO keyboards), CIRCUMFLEX ACCENT and
+                              *   DEGREE SIGN in a German layout (Mac: only on
+                              *   ISO keyboards), SUPERSCRIPT TWO and TILDE in a
+                              *   French Windows layout, COMMERCIAL AT and
+                              *   NUMBER SIGN in a French Mac layout on ISO
+                              *   keyboards, and LESS-THAN SIGN and GREATER-THAN
+                              *   SIGN in a Swiss German, German, or French Mac
+                              *   layout on ANSI keyboards.
+                              */
+    SDL2_SCANCODE_COMMA = 54,
+    SDL2_SCANCODE_PERIOD = 55,
+    SDL2_SCANCODE_SLASH = 56,
+
+    SDL2_SCANCODE_CAPSLOCK = 57,
+
+    SDL2_SCANCODE_F1 = 58,
+    SDL2_SCANCODE_F2 = 59,
+    SDL2_SCANCODE_F3 = 60,
+    SDL2_SCANCODE_F4 = 61,
+    SDL2_SCANCODE_F5 = 62,
+    SDL2_SCANCODE_F6 = 63,
+    SDL2_SCANCODE_F7 = 64,
+    SDL2_SCANCODE_F8 = 65,
+    SDL2_SCANCODE_F9 = 66,
+    SDL2_SCANCODE_F10 = 67,
+    SDL2_SCANCODE_F11 = 68,
+    SDL2_SCANCODE_F12 = 69,
+
+    SDL2_SCANCODE_PRINTSCREEN = 70,
+    SDL2_SCANCODE_SCROLLLOCK = 71,
+    SDL2_SCANCODE_PAUSE = 72,
+    SDL2_SCANCODE_INSERT = 73, /**< insert on PC, help on some Mac keyboards (but
+                                   does send code 73, not 117) */
+    SDL2_SCANCODE_HOME = 74,
+    SDL2_SCANCODE_PAGEUP = 75,
+    SDL2_SCANCODE_DELETE = 76,
+    SDL2_SCANCODE_END = 77,
+    SDL2_SCANCODE_PAGEDOWN = 78,
+    SDL2_SCANCODE_RIGHT = 79,
+    SDL2_SCANCODE_LEFT = 80,
+    SDL2_SCANCODE_DOWN = 81,
+    SDL2_SCANCODE_UP = 82,
+
+    SDL2_SCANCODE_NUMLOCKCLEAR = 83, /**< num lock on PC, clear on Mac keyboards
+                                     */
+    SDL2_SCANCODE_KP_DIVIDE = 84,
+    SDL2_SCANCODE_KP_MULTIPLY = 85,
+    SDL2_SCANCODE_KP_MINUS = 86,
+    SDL2_SCANCODE_KP_PLUS = 87,
+    SDL2_SCANCODE_KP_ENTER = 88,
+    SDL2_SCANCODE_KP_1 = 89,
+    SDL2_SCANCODE_KP_2 = 90,
+    SDL2_SCANCODE_KP_3 = 91,
+    SDL2_SCANCODE_KP_4 = 92,
+    SDL2_SCANCODE_KP_5 = 93,
+    SDL2_SCANCODE_KP_6 = 94,
+    SDL2_SCANCODE_KP_7 = 95,
+    SDL2_SCANCODE_KP_8 = 96,
+    SDL2_SCANCODE_KP_9 = 97,
+    SDL2_SCANCODE_KP_0 = 98,
+    SDL2_SCANCODE_KP_PERIOD = 99,
+
+    SDL2_SCANCODE_NONUSBACKSLASH = 100, /**< This is the additional key that ISO
+                                        *   keyboards have over ANSI ones,
+                                        *   located between left shift and Y.
+                                        *   Produces GRAVE ACCENT and TILDE in a
+                                        *   US or UK Mac layout, REVERSE SOLIDUS
+                                        *   (backslash) and VERTICAL LINE in a
+                                        *   US or UK Windows layout, and
+                                        *   LESS-THAN SIGN and GREATER-THAN SIGN
+                                        *   in a Swiss German, German, or French
+                                        *   layout. */
+    SDL2_SCANCODE_APPLICATION = 101, /**< windows contextual menu, compose */
+    SDL2_SCANCODE_POWER = 102, /**< The USB document says this is a status flag,
+                               *   not a physical key - but some Mac keyboards
+                               *   do have a power key. */
+    SDL2_SCANCODE_KP_EQUALS = 103,
+    SDL2_SCANCODE_F13 = 104,
+    SDL2_SCANCODE_F14 = 105,
+    SDL2_SCANCODE_F15 = 106,
+    SDL2_SCANCODE_F16 = 107,
+    SDL2_SCANCODE_F17 = 108,
+    SDL2_SCANCODE_F18 = 109,
+    SDL2_SCANCODE_F19 = 110,
+    SDL2_SCANCODE_F20 = 111,
+    SDL2_SCANCODE_F21 = 112,
+    SDL2_SCANCODE_F22 = 113,
+    SDL2_SCANCODE_F23 = 114,
+    SDL2_SCANCODE_F24 = 115,
+    SDL2_SCANCODE_EXECUTE = 116,
+    SDL2_SCANCODE_HELP = 117,    /**< AL Integrated Help Center */
+    SDL2_SCANCODE_MENU = 118,    /**< Menu (show menu) */
+    SDL2_SCANCODE_SELECT = 119,
+    SDL2_SCANCODE_STOP = 120,    /**< AC Stop */
+    SDL2_SCANCODE_AGAIN = 121,   /**< AC Redo/Repeat */
+    SDL2_SCANCODE_UNDO = 122,    /**< AC Undo */
+    SDL2_SCANCODE_CUT = 123,     /**< AC Cut */
+    SDL2_SCANCODE_COPY = 124,    /**< AC Copy */
+    SDL2_SCANCODE_PASTE = 125,   /**< AC Paste */
+    SDL2_SCANCODE_FIND = 126,    /**< AC Find */
+    SDL2_SCANCODE_MUTE = 127,
+    SDL2_SCANCODE_VOLUMEUP = 128,
+    SDL2_SCANCODE_VOLUMEDOWN = 129,
+/* not sure whether there's a reason to enable these */
+/*     SDL2_SCANCODE_LOCKINGCAPSLOCK = 130,  */
+/*     SDL2_SCANCODE_LOCKINGNUMLOCK = 131, */
+/*     SDL2_SCANCODE_LOCKINGSCROLLLOCK = 132, */
+    SDL2_SCANCODE_KP_COMMA = 133,
+    SDL2_SCANCODE_KP_EQUALSAS400 = 134,
+
+    SDL2_SCANCODE_INTERNATIONAL1 = 135, /**< used on Asian keyboards, see
+                                            footnotes in USB doc */
+    SDL2_SCANCODE_INTERNATIONAL2 = 136,
+    SDL2_SCANCODE_INTERNATIONAL3 = 137, /**< Yen */
+    SDL2_SCANCODE_INTERNATIONAL4 = 138,
+    SDL2_SCANCODE_INTERNATIONAL5 = 139,
+    SDL2_SCANCODE_INTERNATIONAL6 = 140,
+    SDL2_SCANCODE_INTERNATIONAL7 = 141,
+    SDL2_SCANCODE_INTERNATIONAL8 = 142,
+    SDL2_SCANCODE_INTERNATIONAL9 = 143,
+    SDL2_SCANCODE_LANG1 = 144, /**< Hangul/English toggle */
+    SDL2_SCANCODE_LANG2 = 145, /**< Hanja conversion */
+    SDL2_SCANCODE_LANG3 = 146, /**< Katakana */
+    SDL2_SCANCODE_LANG4 = 147, /**< Hiragana */
+    SDL2_SCANCODE_LANG5 = 148, /**< Zenkaku/Hankaku */
+    SDL2_SCANCODE_LANG6 = 149, /**< reserved */
+    SDL2_SCANCODE_LANG7 = 150, /**< reserved */
+    SDL2_SCANCODE_LANG8 = 151, /**< reserved */
+    SDL2_SCANCODE_LANG9 = 152, /**< reserved */
+
+    SDL2_SCANCODE_ALTERASE = 153,    /**< Erase-Eaze */
+    SDL2_SCANCODE_SYSREQ = 154,
+    SDL2_SCANCODE_CANCEL = 155,      /**< AC Cancel */
+    SDL2_SCANCODE_CLEAR = 156,
+    SDL2_SCANCODE_PRIOR = 157,
+    SDL2_SCANCODE_RETURN2 = 158,
+    SDL2_SCANCODE_SEPARATOR = 159,
+    SDL2_SCANCODE_OUT = 160,
+    SDL2_SCANCODE_OPER = 161,
+    SDL2_SCANCODE_CLEARAGAIN = 162,
+    SDL2_SCANCODE_CRSEL = 163,
+    SDL2_SCANCODE_EXSEL = 164,
+
+    SDL2_SCANCODE_KP_00 = 176,
+    SDL2_SCANCODE_KP_000 = 177,
+    SDL2_SCANCODE_THOUSANDSSEPARATOR = 178,
+    SDL2_SCANCODE_DECIMALSEPARATOR = 179,
+    SDL2_SCANCODE_CURRENCYUNIT = 180,
+    SDL2_SCANCODE_CURRENCYSUBUNIT = 181,
+    SDL2_SCANCODE_KP_LEFTPAREN = 182,
+    SDL2_SCANCODE_KP_RIGHTPAREN = 183,
+    SDL2_SCANCODE_KP_LEFTBRACE = 184,
+    SDL2_SCANCODE_KP_RIGHTBRACE = 185,
+    SDL2_SCANCODE_KP_TAB = 186,
+    SDL2_SCANCODE_KP_BACKSPACE = 187,
+    SDL2_SCANCODE_KP_A = 188,
+    SDL2_SCANCODE_KP_B = 189,
+    SDL2_SCANCODE_KP_C = 190,
+    SDL2_SCANCODE_KP_D = 191,
+    SDL2_SCANCODE_KP_E = 192,
+    SDL2_SCANCODE_KP_F = 193,
+    SDL2_SCANCODE_KP_XOR = 194,
+    SDL2_SCANCODE_KP_POWER = 195,
+    SDL2_SCANCODE_KP_PERCENT = 196,
+    SDL2_SCANCODE_KP_LESS = 197,
+    SDL2_SCANCODE_KP_GREATER = 198,
+    SDL2_SCANCODE_KP_AMPERSAND = 199,
+    SDL2_SCANCODE_KP_DBLAMPERSAND = 200,
+    SDL2_SCANCODE_KP_VERTICALBAR = 201,
+    SDL2_SCANCODE_KP_DBLVERTICALBAR = 202,
+    SDL2_SCANCODE_KP_COLON = 203,
+    SDL2_SCANCODE_KP_HASH = 204,
+    SDL2_SCANCODE_KP_SPACE = 205,
+    SDL2_SCANCODE_KP_AT = 206,
+    SDL2_SCANCODE_KP_EXCLAM = 207,
+    SDL2_SCANCODE_KP_MEMSTORE = 208,
+    SDL2_SCANCODE_KP_MEMRECALL = 209,
+    SDL2_SCANCODE_KP_MEMCLEAR = 210,
+    SDL2_SCANCODE_KP_MEMADD = 211,
+    SDL2_SCANCODE_KP_MEMSUBTRACT = 212,
+    SDL2_SCANCODE_KP_MEMMULTIPLY = 213,
+    SDL2_SCANCODE_KP_MEMDIVIDE = 214,
+    SDL2_SCANCODE_KP_PLUSMINUS = 215,
+    SDL2_SCANCODE_KP_CLEAR = 216,
+    SDL2_SCANCODE_KP_CLEARENTRY = 217,
+    SDL2_SCANCODE_KP_BINARY = 218,
+    SDL2_SCANCODE_KP_OCTAL = 219,
+    SDL2_SCANCODE_KP_DECIMAL = 220,
+    SDL2_SCANCODE_KP_HEXADECIMAL = 221,
+
+    SDL2_SCANCODE_LCTRL = 224,
+    SDL2_SCANCODE_LSHIFT = 225,
+    SDL2_SCANCODE_LALT = 226, /**< alt, option */
+    SDL2_SCANCODE_LGUI = 227, /**< windows, command (apple), meta */
+    SDL2_SCANCODE_RCTRL = 228,
+    SDL2_SCANCODE_RSHIFT = 229,
+    SDL2_SCANCODE_RALT = 230, /**< alt gr, option */
+    SDL2_SCANCODE_RGUI = 231, /**< windows, command (apple), meta */
+
+    SDL2_SCANCODE_MODE = 257,    /**< I'm not sure if this is really not covered
+                                 *   by any of the above, but since there's a
+                                 *   special KMOD_MODE for it I'm adding it here
+                                 */
+
+    /* @} *//* Usage page 0x07 */
+
+    /**
+     *  \name Usage page 0x0C
+     *
+     *  These values are mapped from usage page 0x0C (USB consumer page).
+     *  See https://usb.org/sites/default/files/hut1_2.pdf
+     *
+     *  There are way more keys in the spec than we can represent in the
+     *  current scancode range, so pick the ones that commonly come up in
+     *  real world usage.
+     */
+    /* @{ */
+
+    SDL2_SCANCODE_AUDIONEXT = 258,
+    SDL2_SCANCODE_AUDIOPREV = 259,
+    SDL2_SCANCODE_AUDIOSTOP = 260,
+    SDL2_SCANCODE_AUDIOPLAY = 261,
+    SDL2_SCANCODE_AUDIOMUTE = 262,
+    SDL2_SCANCODE_MEDIASELECT = 263,
+    SDL2_SCANCODE_WWW = 264,             /**< AL Internet Browser */
+    SDL2_SCANCODE_MAIL = 265,
+    SDL2_SCANCODE_CALCULATOR = 266,      /**< AL Calculator */
+    SDL2_SCANCODE_COMPUTER = 267,
+    SDL2_SCANCODE_AC_SEARCH = 268,       /**< AC Search */
+    SDL2_SCANCODE_AC_HOME = 269,         /**< AC Home */
+    SDL2_SCANCODE_AC_BACK = 270,         /**< AC Back */
+    SDL2_SCANCODE_AC_FORWARD = 271,      /**< AC Forward */
+    SDL2_SCANCODE_AC_STOP = 272,         /**< AC Stop */
+    SDL2_SCANCODE_AC_REFRESH = 273,      /**< AC Refresh */
+    SDL2_SCANCODE_AC_BOOKMARKS = 274,    /**< AC Bookmarks */
+
+    /* @} *//* Usage page 0x0C */
+
+    /**
+     *  \name Walther keys
+     *
+     *  These are values that Christian Walther added (for mac keyboard?).
+     */
+    /* @{ */
+
+    SDL2_SCANCODE_BRIGHTNESSDOWN = 275,
+    SDL2_SCANCODE_BRIGHTNESSUP = 276,
+    SDL2_SCANCODE_DISPLAYSWITCH = 277, /**< display mirroring/dual display
+                                           switch, video mode switch */
+    SDL2_SCANCODE_KBDILLUMTOGGLE = 278,
+    SDL2_SCANCODE_KBDILLUMDOWN = 279,
+    SDL2_SCANCODE_KBDILLUMUP = 280,
+    SDL2_SCANCODE_EJECT = 281,
+    SDL2_SCANCODE_SLEEP = 282,           /**< SC System Sleep */
+
+    SDL2_SCANCODE_APP1 = 283,
+    SDL2_SCANCODE_APP2 = 284,
+
+    /* @} *//* Walther keys */
+
+    /**
+     *  \name Usage page 0x0C (additional media keys)
+     *
+     *  These values are mapped from usage page 0x0C (USB consumer page).
+     */
+    /* @{ */
+
+    SDL2_SCANCODE_AUDIOREWIND = 285,
+    SDL2_SCANCODE_AUDIOFASTFORWARD = 286,
+
+    /* @} *//* Usage page 0x0C (additional media keys) */
+
+    /**
+     *  \name Mobile keys
+     *
+     *  These are values that are often used on mobile phones.
+     */
+    /* @{ */
+
+    SDL2_SCANCODE_SOFTLEFT = 287, /**< Usually situated below the display on phones and
+                                      used as a multi-function feature key for selecting
+                                      a software defined function shown on the bottom left
+                                      of the display. */
+    SDL2_SCANCODE_SOFTRIGHT = 288, /**< Usually situated below the display on phones and
+                                       used as a multi-function feature key for selecting
+                                       a software defined function shown on the bottom right
+                                       of the display. */
+    SDL2_SCANCODE_CALL = 289, /**< Used for accepting phone calls. */
+    SDL2_SCANCODE_ENDCALL = 290, /**< Used for rejecting phone calls. */
+
+    /* @} *//* Mobile keys */
+
+    /* Add any other keys here. */
+
+    SDL2_NUM_SCANCODES = 512 /**< not a key, just marks the number of scancodes
+                                 for array bounds */
+} SDL2_Scancode;
+
+typedef struct SDL2_Keysym
+{
+    SDL2_Scancode scancode;
+    SDL_Keycode sym;
+    SDL_Keymod mod;
+    Uint16 raw;
+} SDL2_Keysym;
+
 typedef SDL_EventAction SDL_eventaction;
 typedef union SDL2_Event SDL2_Event;
 typedef int (SDLCALL *SDL2_EventFilter) (void *userdata, SDL2_Event *event);
diff --git a/src/sdl2_protos.h b/src/sdl2_protos.h
index 0deef59..9475d03 100644
--- a/src/sdl2_protos.h
+++ b/src/sdl2_protos.h
@@ -240,10 +240,10 @@ SDL2_PROTO(SDL_Window*,GetKeyboardFocus,(void))
 SDL2_PROTO(const Uint8*,GetKeyboardState,(int *a))
 SDL2_PROTO(SDL2_Keymod,GetModState,(void))
 SDL2_PROTO(void,SetModState,(SDL2_Keymod a))
-SDL2_PROTO(SDL_Keycode,GetKeyFromScancode,(SDL_Scancode a))
-SDL2_PROTO(SDL_Scancode,GetScancodeFromKey,(SDL_Keycode a))
-SDL2_PROTO(const char*,GetScancodeName,(SDL_Scancode a))
-SDL2_PROTO(SDL_Scancode,GetScancodeFromName,(const char *a))
+SDL2_PROTO(SDL_Keycode,GetKeyFromScancode,(SDL2_Scancode a))
+SDL2_PROTO(SDL2_Scancode,GetScancodeFromKey,(SDL_Keycode a))
+SDL2_PROTO(const char*,GetScancodeName,(SDL2_Scancode a))
+SDL2_PROTO(SDL2_Scancode,GetScancodeFromName,(const char *a))
 SDL2_PROTO(const char*,GetKeyName,(SDL_Keycode a))
 SDL2_PROTO(SDL_Keycode,GetKeyFromName,(const char *a))
 SDL2_PROTO(void,StartTextInput,(void))
diff --git a/src/sdl3_include_wrapper.h b/src/sdl3_include_wrapper.h
index 0f42a54..40c7445 100644
--- a/src/sdl3_include_wrapper.h
+++ b/src/sdl3_include_wrapper.h
@@ -242,6 +242,7 @@
 #define SDL_GetDefaultAssertionHandler IGNORE_THIS_VERSION_OF_SDL_GetDefaultAssertionHandler
 #define SDL_GetDefaultCursor IGNORE_THIS_VERSION_OF_SDL_GetDefaultCursor
 #define SDL_GetDefaultKeyFromScancode IGNORE_THIS_VERSION_OF_SDL_GetDefaultKeyFromScancode
+#define SDL_GetDefaultScancodeFromKey IGNORE_THIS_VERSION_OF_SDL_GetDefaultScancodeFromKey
 #define SDL_GetDesktopDisplayMode IGNORE_THIS_VERSION_OF_SDL_GetDesktopDisplayMode
 #define SDL_GetDisplayBounds IGNORE_THIS_VERSION_OF_SDL_GetDisplayBounds
 #define SDL_GetDisplayContentScale IGNORE_THIS_VERSION_OF_SDL_GetDisplayContentScale
@@ -764,6 +765,7 @@
 #define SDL_SetRenderVSync IGNORE_THIS_VERSION_OF_SDL_SetRenderVSync
 #define SDL_SetRenderViewport IGNORE_THIS_VERSION_OF_SDL_SetRenderViewport
 #define SDL_SetStringProperty IGNORE_THIS_VERSION_OF_SDL_SetStringProperty
+#define SDL_SetScancodeName IGNORE_THIS_VERSION_OF_SDL_SetScancodeName
 #define SDL_SetSurfaceAlphaMod IGNORE_THIS_VERSION_OF_SDL_SetSurfaceAlphaMod
 #define SDL_SetSurfaceBlendMode IGNORE_THIS_VERSION_OF_SDL_SetSurfaceBlendMode
 #define SDL_SetSurfaceClipRect IGNORE_THIS_VERSION_OF_SDL_SetSurfaceClipRect
@@ -1910,6 +1912,10 @@
 #undef SDL_GetDefaultKeyFromScancode
 #endif
 
+#ifdef SDL_GetDefaultScancodeFromKey
+#undef SDL_GetDefaultScancodeFromKey
+#endif
+
 #ifdef SDL_GetDesktopDisplayMode
 #undef SDL_GetDesktopDisplayMode
 #endif
@@ -3998,6 +4004,10 @@
 #undef SDL_SetStringProperty
 #endif
 
+#ifdef SDL_SetScancodeName
+#undef SDL_SetScancodeName
+#endif
+
 #ifdef SDL_SetSurfaceAlphaMod
 #undef SDL_SetSurfaceAlphaMod
 #endif
diff --git a/src/sdl3_syms.h b/src/sdl3_syms.h
index 750331d..bea848f 100644
--- a/src/sdl3_syms.h
+++ b/src/sdl3_syms.h
@@ -217,12 +217,12 @@ SDL3_SYM_PASSTHROUGH(SDL_Window*,GetKeyboardFocus,(void),(),return)
 SDL3_SYM_PASSTHROUGH(const Uint8*,GetKeyboardState,(int *a),(a),return)
 SDL3_SYM(SDL_Keymod,GetModState,(void),(),return)
 SDL3_SYM(void,SetModState,(SDL_Keymod a),(a),)
-SDL3_SYM_PASSTHROUGH(SDL_Keycode,GetKeyFromScancode,(SDL_Scancode a),(a),return)
-SDL3_SYM_PASSTHROUGH(SDL_Scancode,GetScancodeFromKey,(SDL_Keycode a),(a),return)
-SDL3_SYM_PASSTHROUGH(const char*,GetScancodeName,(SDL_Scancode a),(a),return)
-SDL3_SYM_PASSTHROUGH(SDL_Scancode,GetScancodeFromName,(const char *a),(a),return)
-SDL3_SYM_PASSTHROUGH(const char*,GetKeyName,(SDL_Keycode a),(a),return)
-SDL3_SYM_PASSTHROUGH(SDL_Keycode,GetKeyFromName,(const char *a),(a),return)
+SDL3_SYM(SDL_Keycode,GetKeyFromScancode,(SDL_Scancode a, SDL_Keymod b),(a,b),return)
+SDL3_SYM(SDL_Scancode,GetScancodeFromKey,(SDL_Keycode a, SDL_Keymod *b),(a,b),return)
+SDL3_SYM(const char*,GetScancodeName,(SDL_Scancode a),(a),return)
+SDL3_SYM(SDL_Scancode,GetScancodeFromName,(const char *a),(a),return)
+SDL3_SYM(const char*,GetKeyName,(SDL_Keycode a),(a),return)
+SDL3_SYM(SDL_Keycode,GetKeyFromName,(const char *a),(a),return)
 SDL3_SYM_PASSTHROUGH(void,StartTextInput,(void),(),)
 SDL3_SYM_RENAMED(SDL_bool,IsTextInputActive,TextInputActive,(void),(),return)
 SDL3_SYM_PASSTHROUGH(void,StopTextInput,(void),(),)