SDL: Numpad scancodes have non-numpad keycodes

From d4497ecdbdfd4567eebddde2c3773e1a1cba4894 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sun, 30 Jun 2024 23:35:23 -0700
Subject: [PATCH] Numpad scancodes have non-numpad keycodes

This allows the numpad to work as the user expects based on the numlock state. If the application needs to distinguish the keys, it can check to see whether the scancode is a numpad key or not.
---
 include/SDL3/SDL_keycode.h                  |  42 +-
 src/events/SDL_keyboard.c                   |   4 +-
 src/events/SDL_keymap.c                     |  89 +++-
 src/video/cocoa/SDL_cocoakeyboard.m         |   2 +-
 src/video/emscripten/SDL_emscriptenevents.c | 496 +++++++++-----------
 src/video/wayland/SDL_waylandevents.c       |   2 +-
 src/video/windows/SDL_windowskeyboard.c     |   8 +-
 src/video/x11/SDL_x11keyboard.c             |  25 +-
 8 files changed, 316 insertions(+), 352 deletions(-)

diff --git a/include/SDL3/SDL_keycode.h b/include/SDL3/SDL_keycode.h
index ef612ab4edaed..a98bc08dd393d 100644
--- a/include/SDL3/SDL_keycode.h
+++ b/include/SDL3/SDL_keycode.h
@@ -125,6 +125,7 @@ typedef Uint32 SDL_Keycode;
 #define SDLK_RIGHTBRACE             0x0000007du /* '}' */
 #define SDLK_TILDE                  0x0000007eu /* '~' */
 #define SDLK_DELETE                 0x0000007fu /* '\x7F' */
+#define SDLK_PLUSMINUS              0x000000b1u /* '±' */
 #define SDLK_CAPSLOCK               0x40000039u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CAPSLOCK) */
 #define SDLK_F1                     0x4000003au /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F1) */
 #define SDLK_F2                     0x4000003bu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F2) */
@@ -151,25 +152,8 @@ typedef Uint32 SDL_Keycode;
 #define SDLK_DOWN                   0x40000051u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_DOWN) */
 #define SDLK_UP                     0x40000052u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_UP) */
 #define SDLK_NUMLOCKCLEAR           0x40000053u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_NUMLOCKCLEAR) */
-#define SDLK_KP_DIVIDE              0x40000054u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_DIVIDE) */
-#define SDLK_KP_MULTIPLY            0x40000055u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MULTIPLY) */
-#define SDLK_KP_MINUS               0x40000056u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MINUS) */
-#define SDLK_KP_PLUS                0x40000057u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_PLUS) */
-#define SDLK_KP_ENTER               0x40000058u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_ENTER) */
-#define SDLK_KP_1                   0x40000059u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_1) */
-#define SDLK_KP_2                   0x4000005au /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_2) */
-#define SDLK_KP_3                   0x4000005bu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_3) */
-#define SDLK_KP_4                   0x4000005cu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_4) */
-#define SDLK_KP_5                   0x4000005du /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_5) */
-#define SDLK_KP_6                   0x4000005eu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_6) */
-#define SDLK_KP_7                   0x4000005fu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_7) */
-#define SDLK_KP_8                   0x40000060u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_8) */
-#define SDLK_KP_9                   0x40000061u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_9) */
-#define SDLK_KP_0                   0x40000062u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_0) */
-#define SDLK_KP_PERIOD              0x40000063u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_PERIOD) */
 #define SDLK_APPLICATION            0x40000065u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_APPLICATION) */
 #define SDLK_POWER                  0x40000066u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_POWER) */
-#define SDLK_KP_EQUALS              0x40000067u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_EQUALS) */
 #define SDLK_F13                    0x40000068u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F13) */
 #define SDLK_F14                    0x40000069u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F14) */
 #define SDLK_F15                    0x4000006au /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_F15) */
@@ -196,8 +180,6 @@ typedef Uint32 SDL_Keycode;
 #define SDLK_MUTE                   0x4000007fu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_MUTE) */
 #define SDLK_VOLUMEUP               0x40000080u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_VOLUMEUP) */
 #define SDLK_VOLUMEDOWN             0x40000081u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_VOLUMEDOWN) */
-#define SDLK_KP_COMMA               0x40000085u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_COMMA) */
-#define SDLK_KP_EQUALSAS400         0x40000086u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_EQUALSAS400) */
 #define SDLK_ALTERASE               0x40000099u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_ALTERASE) */
 #define SDLK_SYSREQ                 0x4000009au /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_SYSREQ) */
 #define SDLK_CANCEL                 0x4000009bu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CANCEL) */
@@ -216,32 +198,11 @@ typedef Uint32 SDL_Keycode;
 #define SDLK_DECIMALSEPARATOR       0x400000b3u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_DECIMALSEPARATOR) */
 #define SDLK_CURRENCYUNIT           0x400000b4u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CURRENCYUNIT) */
 #define SDLK_CURRENCYSUBUNIT        0x400000b5u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_CURRENCYSUBUNIT) */
-#define SDLK_KP_LEFTPAREN           0x400000b6u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_LEFTPAREN) */
-#define SDLK_KP_RIGHTPAREN          0x400000b7u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_RIGHTPAREN) */
-#define SDLK_KP_LEFTBRACE           0x400000b8u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_LEFTBRACE) */
-#define SDLK_KP_RIGHTBRACE          0x400000b9u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_RIGHTBRACE) */
-#define SDLK_KP_TAB                 0x400000bau /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_TAB) */
-#define SDLK_KP_BACKSPACE           0x400000bbu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_BACKSPACE) */
-#define SDLK_KP_A                   0x400000bcu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_A) */
-#define SDLK_KP_B                   0x400000bdu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_B) */
-#define SDLK_KP_C                   0x400000beu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_C) */
-#define SDLK_KP_D                   0x400000bfu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_D) */
-#define SDLK_KP_E                   0x400000c0u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_E) */
-#define SDLK_KP_F                   0x400000c1u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_F) */
 #define SDLK_KP_XOR                 0x400000c2u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_XOR) */
 #define SDLK_KP_POWER               0x400000c3u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_POWER) */
-#define SDLK_KP_PERCENT             0x400000c4u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_PERCENT) */
-#define SDLK_KP_LESS                0x400000c5u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_LESS) */
-#define SDLK_KP_GREATER             0x400000c6u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_GREATER) */
-#define SDLK_KP_AMPERSAND           0x400000c7u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_AMPERSAND) */
 #define SDLK_KP_DBLAMPERSAND        0x400000c8u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_DBLAMPERSAND) */
 #define SDLK_KP_VERTICALBAR         0x400000c9u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_VERTICALBAR) */
 #define SDLK_KP_DBLVERTICALBAR      0x400000cau /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_DBLVERTICALBAR) */
-#define SDLK_KP_COLON               0x400000cbu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_COLON) */
-#define SDLK_KP_HASH                0x400000ccu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_HASH) */
-#define SDLK_KP_SPACE               0x400000cdu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_SPACE) */
-#define SDLK_KP_AT                  0x400000ceu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_AT) */
-#define SDLK_KP_EXCLAM              0x400000cfu /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_EXCLAM) */
 #define SDLK_KP_MEMSTORE            0x400000d0u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMSTORE) */
 #define SDLK_KP_MEMRECALL           0x400000d1u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMRECALL) */
 #define SDLK_KP_MEMCLEAR            0x400000d2u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMCLEAR) */
@@ -249,7 +210,6 @@ typedef Uint32 SDL_Keycode;
 #define SDLK_KP_MEMSUBTRACT         0x400000d4u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMSUBTRACT) */
 #define SDLK_KP_MEMMULTIPLY         0x400000d5u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMMULTIPLY) */
 #define SDLK_KP_MEMDIVIDE           0x400000d6u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMDIVIDE) */
-#define SDLK_KP_PLUSMINUS           0x400000d7u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_PLUSMINUS) */
 #define SDLK_KP_CLEAR               0x400000d8u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_CLEAR) */
 #define SDLK_KP_CLEARENTRY          0x400000d9u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_CLEARENTRY) */
 #define SDLK_KP_BINARY              0x400000dau /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_BINARY) */
diff --git a/src/events/SDL_keyboard.c b/src/events/SDL_keyboard.c
index f3530a27040a5..87a57e40d2c3a 100644
--- a/src/events/SDL_keyboard.c
+++ b/src/events/SDL_keyboard.c
@@ -334,8 +334,8 @@ static SDL_Keycode SDL_GetEventKeycode(SDL_Keyboard *keyboard, SDL_Scancode scan
 {
     SDL_bool shifted = (modstate & SDL_KMOD_SHIFT) != 0;
 
-    // We won't be applying any modifiers by default
-    modstate = SDL_KMOD_NONE;
+    // We won't be applying any modifiers except numlock by default
+    modstate &= SDL_KMOD_NUM;
 
     if (scancode >= SDL_SCANCODE_A && scancode <= SDL_SCANCODE_Z) {
         if (keyboard->non_latin_letters && (keyboard->keycode_options & KEYCODE_OPTION_LATIN_LETTERS)) {
diff --git a/src/events/SDL_keymap.c b/src/events/SDL_keymap.c
index 4249465cfaec0..c1eb39bf5112d 100644
--- a/src/events/SDL_keymap.c
+++ b/src/events/SDL_keymap.c
@@ -236,11 +236,94 @@ SDL_Keycode SDL_GetDefaultKeyFromScancode(SDL_Scancode scancode, SDL_Keymod mods
         }
     }
 
-    if (scancode == SDL_SCANCODE_DELETE) {
+    switch (scancode) {
+    case SDL_SCANCODE_DELETE:
         return SDLK_DELETE;
+    case SDL_SCANCODE_KP_DIVIDE:
+        return SDLK_SLASH;
+    case SDL_SCANCODE_KP_MULTIPLY:
+        return SDLK_ASTERISK;
+    case SDL_SCANCODE_KP_MINUS:
+        return SDLK_MINUS;
+    case SDL_SCANCODE_KP_PLUS:
+        return SDLK_PLUS;
+    case SDL_SCANCODE_KP_ENTER:
+        return SDLK_RETURN;
+    case SDL_SCANCODE_KP_1:
+        return (modstate & SDL_KMOD_NUM) ? SDLK_1 : SDLK_END;
+    case SDL_SCANCODE_KP_2:
+        return (modstate & SDL_KMOD_NUM) ? SDLK_2 : SDLK_DOWN;
+    case SDL_SCANCODE_KP_3:
+        return (modstate & SDL_KMOD_NUM) ? SDLK_3 : SDLK_PAGEDOWN;
+    case SDL_SCANCODE_KP_4:
+        return (modstate & SDL_KMOD_NUM) ? SDLK_4 : SDLK_LEFT;
+    case SDL_SCANCODE_KP_5:
+        return (modstate & SDL_KMOD_NUM) ? SDLK_5 : SDLK_CLEAR;
+    case SDL_SCANCODE_KP_6:
+        return (modstate & SDL_KMOD_NUM) ? SDLK_6 : SDLK_RIGHT;
+    case SDL_SCANCODE_KP_7:
+        return (modstate & SDL_KMOD_NUM) ? SDLK_7 : SDLK_HOME;
+    case SDL_SCANCODE_KP_8:
+        return (modstate & SDL_KMOD_NUM) ? SDLK_8 : SDLK_UP;
+    case SDL_SCANCODE_KP_9:
+        return (modstate & SDL_KMOD_NUM) ? SDLK_9 : SDLK_PAGEUP;
+    case SDL_SCANCODE_KP_0:
+        return (modstate & SDL_KMOD_NUM) ? SDLK_0 : SDLK_INSERT;
+    case SDL_SCANCODE_KP_PERIOD:
+        return (modstate & SDL_KMOD_NUM) ? SDLK_PERIOD : SDLK_DELETE;
+    case SDL_SCANCODE_KP_EQUALS:
+        return SDLK_EQUALS;
+    case SDL_SCANCODE_KP_COMMA:
+        return SDLK_COMMA;
+    case SDL_SCANCODE_KP_EQUALSAS400:
+        return SDLK_EQUALS;
+    case SDL_SCANCODE_KP_LEFTPAREN:
+        return SDLK_LEFTPAREN;
+    case SDL_SCANCODE_KP_RIGHTPAREN:
+        return SDLK_RIGHTPAREN;
+    case SDL_SCANCODE_KP_LEFTBRACE:
+        return SDLK_LEFTBRACE;
+    case SDL_SCANCODE_KP_RIGHTBRACE:
+        return SDLK_RIGHTBRACE;
+    case SDL_SCANCODE_KP_TAB:
+        return SDLK_TAB;
+    case SDL_SCANCODE_KP_BACKSPACE:
+        return SDLK_BACKSPACE;
+    case SDL_SCANCODE_KP_A:
+        return SDLK_A;
+    case SDL_SCANCODE_KP_B:
+        return SDLK_B;
+    case SDL_SCANCODE_KP_C:
+        return SDLK_C;
+    case SDL_SCANCODE_KP_D:
+        return SDLK_D;
+    case SDL_SCANCODE_KP_E:
+        return SDLK_E;
+    case SDL_SCANCODE_KP_F:
+        return SDLK_F;
+    case SDL_SCANCODE_KP_PERCENT:
+        return SDLK_PERCENT;
+    case SDL_SCANCODE_KP_LESS:
+        return SDLK_LESS;
+    case SDL_SCANCODE_KP_GREATER:
+        return SDLK_GREATER;
+    case SDL_SCANCODE_KP_AMPERSAND:
+        return SDLK_AMPERSAND;
+    case SDL_SCANCODE_KP_COLON:
+        return SDLK_COLON;
+    case SDL_SCANCODE_KP_HASH:
+        return SDLK_HASH;
+    case SDL_SCANCODE_KP_SPACE:
+        return SDLK_SPACE;
+    case SDL_SCANCODE_KP_AT:
+        return SDLK_AT;
+    case SDL_SCANCODE_KP_EXCLAM:
+        return SDLK_EXCLAIM;
+    case SDL_SCANCODE_KP_PLUSMINUS:
+        return SDLK_PLUSMINUS;
+    default:
+        return SDL_SCANCODE_TO_KEYCODE(scancode);
     }
-
-    return SDL_SCANCODE_TO_KEYCODE(scancode);
 }
 
 SDL_Scancode SDL_GetDefaultScancodeFromKey(SDL_Keycode key, SDL_Keymod *modstate)
diff --git a/src/video/cocoa/SDL_cocoakeyboard.m b/src/video/cocoa/SDL_cocoakeyboard.m
index bda67f2884cde..c575346f80ff0 100644
--- a/src/video/cocoa/SDL_cocoakeyboard.m
+++ b/src/video/cocoa/SDL_cocoakeyboard.m
@@ -288,7 +288,7 @@ static void UpdateKeymap(SDL_CocoaVideoData *data, SDL_bool send_event)
             /* Make sure this scancode is a valid character scancode */
             SDL_Scancode scancode = darwin_scancode_table[i];
             if (scancode == SDL_SCANCODE_UNKNOWN ||
-                (SDL_GetDefaultKeyFromScancode(scancode, SDL_KMOD_NONE) & SDLK_SCANCODE_MASK)) {
+                scancode >= SDL_SCANCODE_CAPSLOCK) {
                 continue;
             }
 
diff --git a/src/video/emscripten/SDL_emscriptenevents.c b/src/video/emscripten/SDL_emscriptenevents.c
index 4ccf8167839d6..0e79d6d843c6e 100644
--- a/src/video/emscripten/SDL_emscriptenevents.c
+++ b/src/video/emscripten/SDL_emscriptenevents.c
@@ -39,229 +39,229 @@
 https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode
 */
 static const SDL_Keycode emscripten_keycode_table[] = {
-    /*  0 */ SDLK_UNKNOWN,
-    /*  1 */ SDLK_UNKNOWN,
-    /*  2 */ SDLK_UNKNOWN,
-    /*  3 */ SDLK_CANCEL,
-    /*  4 */ SDLK_UNKNOWN,
-    /*  5 */ SDLK_UNKNOWN,
-    /*  6 */ SDLK_HELP,
-    /*  7 */ SDLK_UNKNOWN,
-    /*  8 */ SDLK_BACKSPACE,
-    /*  9 */ SDLK_TAB,
-    /*  10 */ SDLK_UNKNOWN,
-    /*  11 */ SDLK_UNKNOWN,
-    /*  12 */ SDLK_KP_5,
-    /*  13 */ SDLK_RETURN,
-    /*  14 */ SDLK_UNKNOWN,
-    /*  15 */ SDLK_UNKNOWN,
-    /*  16 */ SDLK_LSHIFT,
-    /*  17 */ SDLK_LCTRL,
-    /*  18 */ SDLK_LALT,
-    /*  19 */ SDLK_PAUSE,
-    /*  20 */ SDLK_CAPSLOCK,
-    /*  21 */ SDLK_UNKNOWN,
-    /*  22 */ SDLK_UNKNOWN,
-    /*  23 */ SDLK_UNKNOWN,
-    /*  24 */ SDLK_UNKNOWN,
-    /*  25 */ SDLK_UNKNOWN,
-    /*  26 */ SDLK_UNKNOWN,
-    /*  27 */ SDLK_ESCAPE,
-    /*  28 */ SDLK_UNKNOWN,
-    /*  29 */ SDLK_UNKNOWN,
-    /*  30 */ SDLK_UNKNOWN,
-    /*  31 */ SDLK_UNKNOWN,
-    /*  32 */ SDLK_SPACE,
-    /*  33 */ SDLK_PAGEUP,
-    /*  34 */ SDLK_PAGEDOWN,
-    /*  35 */ SDLK_END,
-    /*  36 */ SDLK_HOME,
-    /*  37 */ SDLK_LEFT,
-    /*  38 */ SDLK_UP,
-    /*  39 */ SDLK_RIGHT,
-    /*  40 */ SDLK_DOWN,
-    /*  41 */ SDLK_UNKNOWN,
-    /*  42 */ SDLK_UNKNOWN,
-    /*  43 */ SDLK_UNKNOWN,
-    /*  44 */ SDLK_UNKNOWN,
-    /*  45 */ SDLK_INSERT,
-    /*  46 */ SDLK_DELETE,
-    /*  47 */ SDLK_UNKNOWN,
-    /*  48 */ SDLK_0,
-    /*  49 */ SDLK_1,
-    /*  50 */ SDLK_2,
-    /*  51 */ SDLK_3,
-    /*  52 */ SDLK_4,
-    /*  53 */ SDLK_5,
-    /*  54 */ SDLK_6,
-    /*  55 */ SDLK_7,
-    /*  56 */ SDLK_8,
-    /*  57 */ SDLK_9,
-    /*  58 */ SDLK_UNKNOWN,
-    /*  59 */ SDLK_SEMICOLON,
-    /*  60 */ SDLK_BACKSLASH /*SDL_SCANCODE_NONUSBACKSLASH*/,
-    /*  61 */ SDLK_EQUALS,
-    /*  62 */ SDLK_UNKNOWN,
-    /*  63 */ SDLK_MINUS,
-    /*  64 */ SDLK_UNKNOWN,
-    /*  65 */ SDLK_A,
-    /*  66 */ SDLK_B,
-    /*  67 */ SDLK_C,
-    /*  68 */ SDLK_D,
-    /*  69 */ SDLK_E,
-    /*  70 */ SDLK_F,
-    /*  71 */ SDLK_G,
-    /*  72 */ SDLK_H,
-    /*  73 */ SDLK_I,
-    /*  74 */ SDLK_J,
-    /*  75 */ SDLK_K,
-    /*  76 */ SDLK_L,
-    /*  77 */ SDLK_M,
-    /*  78 */ SDLK_N,
-    /*  79 */ SDLK_O,
-    /*  80 */ SDLK_P,
-    /*  81 */ SDLK_Q,
-    /*  82 */ SDLK_R,
-    /*  83 */ SDLK_S,
-    /*  84 */ SDLK_T,
-    /*  85 */ SDLK_U,
-    /*  86 */ SDLK_V,
-    /*  87 */ SDLK_W,
-    /*  88 */ SDLK_X,
-    /*  89 */ SDLK_Y,
-    /*  90 */ SDLK_Z,
-    /*  91 */ SDLK_LGUI,
-    /*  92 */ SDLK_UNKNOWN,
-    /*  93 */ SDLK_APPLICATION,
-    /*  94 */ SDLK_UNKNOWN,
-    /*  95 */ SDLK_UNKNOWN,
-    /*  96 */ SDLK_KP_0,
-    /*  97 */ SDLK_KP_1,
-    /*  98 */ SDLK_KP_2,
-    /*  99 */ SDLK_KP_3,
-    /* 100 */ SDLK_KP_4,
-    /* 101 */ SDLK_KP_5,
-    /* 102 */ SDLK_KP_6,
-    /* 103 */ SDLK_KP_7,
-    /* 104 */ SDLK_KP_8,
-    /* 105 */ SDLK_KP_9,
-    /* 106 */ SDLK_KP_MULTIPLY,
-    /* 107 */ SDLK_KP_PLUS,
-    /* 108 */ SDLK_UNKNOWN,
-    /* 109 */ SDLK_KP_MINUS,
-    /* 110 */ SDLK_KP_PERIOD,
-    /* 111 */ SDLK_KP_DIVIDE,
-    /* 112 */ SDLK_F1,
-    /* 113 */ SDLK_F2,
-    /* 114 */ SDLK_F3,
-    /* 115 */ SDLK_F4,
-    /* 116 */ SDLK_F5,
-    /* 117 */ SDLK_F6,
-    /* 118 */ SDLK_F7,
-    /* 119 */ SDLK_F8,
-    /* 120 */ SDLK_F9,
-    /* 121 */ SDLK_F10,
-    /* 122 */ SDLK_F11,
-    /* 123 */ SDLK_F12,
-    /* 124 */ SDLK_F13,
-    /* 125 */ SDLK_F14,
-    /* 126 */ SDLK_F15,
-    /* 127 */ SDLK_F16,
-    /* 128 */ SDLK_F17,
-    /* 129 */ SDLK_F18,
-    /* 130 */ SDLK_F19,
-    /* 131 */ SDLK_F20,
-    /* 132 */ SDLK_F21,
-    /* 133 */ SDLK_F22,
-    /* 134 */ SDLK_F23,
-    /* 135 */ SDLK_F24,
-    /* 136 */ SDLK_UNKNOWN,
-    /* 137 */ SDLK_UNKNOWN,
-    /* 138 */ SDLK_UNKNOWN,
-    /* 139 */ SDLK_UNKNOWN,
-    /* 140 */ SDLK_UNKNOWN,
-    /* 141 */ SDLK_UNKNOWN,
-    /* 142 */ SDLK_UNKNOWN,
-    /* 143 */ SDLK_UNKNOWN,
-    /* 144 */ SDLK_NUMLOCKCLEAR,
-    /* 145 */ SDLK_SCROLLLOCK,
-    /* 146 */ SDLK_UNKNOWN,
-    /* 147 */ SDLK_UNKNOWN,
-    /* 148 */ SDLK_UNKNOWN,
-    /* 149 */ SDLK_UNKNOWN,
-    /* 150 */ SDLK_UNKNOWN,
-    /* 151 */ SDLK_UNKNOWN,
-    /* 152 */ SDLK_UNKNOWN,
-    /* 153 */ SDLK_UNKNOWN,
-    /* 154 */ SDLK_UNKNOWN,
-    /* 155 */ SDLK_UNKNOWN,
-    /* 156 */ SDLK_UNKNOWN,
-    /* 157 */ SDLK_UNKNOWN,
-    /* 158 */ SDLK_UNKNOWN,
-    /* 159 */ SDLK_UNKNOWN,
-    /* 160 */ SDLK_GRAVE,
-    /* 161 */ SDLK_UNKNOWN,
-    /* 162 */ SDLK_UNKNOWN,
-    /* 163 */ SDLK_KP_HASH, /*KaiOS phone keypad*/
-    /* 164 */ SDLK_UNKNOWN,
-    /* 165 */ SDLK_UNKNOWN,
-    /* 166 */ SDLK_UNKNOWN,
-    /* 167 */ SDLK_UNKNOWN,
-    /* 168 */ SDLK_UNKNOWN,
-    /* 169 */ SDLK_UNKNOWN,
-    /* 170 */ SDLK_KP_MULTIPLY, /*KaiOS phone keypad*/
-    /* 171 */ SDLK_RIGHTBRACKET,
-    /* 172 */ SDLK_UNKNOWN,
-    /* 173 */ SDLK_MINUS,      /*FX*/
-    /* 174 */ SDLK_VOLUMEDOWN, /*IE, Chrome*/
-    /* 175 */ SDLK_VOLUMEUP,   /*IE, Chrome*/
-    /* 176 */ SDLK_MEDIA_NEXT_TRACK,  /*IE, Chrome*/
-    /* 177 */ SDLK_MEDIA_PREVIOUS_TRACK,  /*IE, Chrome*/
-    /* 178 */ SDLK_UNKNOWN,
-    /* 179 */ SDLK_MEDIA_PLAY, /*IE, Chrome*/
-    /* 180 */ SDLK_UNKNOWN,
-    /* 181 */ SDLK_UNKNOWN,
-    /* 182 */ SDLK_VOLUMEDOWN, /*FX*/
-    /* 183 */ SDLK_VOLUMEUP,   /*FX*/
-    /* 184 */ SDLK_UNKNOWN,
-    /* 185 */ SDLK_UNKNOWN,
-    /* 186 */ SDLK_SEMICOLON, /*IE, Chrome, D3E legacy*/
-    /* 187 */ SDLK_EQUALS,    /*IE, Chrome, D3E legacy*/
-    /* 188 */ SDLK_COMMA,
-    /* 189 */ SDLK_MINUS, /*IE, Chrome, D3E legacy*/
-    /* 190 */ SDLK_PERIOD,
-    /* 191 */ SDLK_SLASH,
-    /* 192 */ SDLK_GRAVE, /*FX, D3E legacy (SDLK_APOSTROPHE in IE/Chrome)*/
-    /* 193 */ SDLK_UNKNOWN,
-    /* 194 */ SDLK_UNKNOWN,
-    /* 195 */ SDLK_UNKNOWN,
-    /* 196 */ SDLK_UNKNOWN,
-    /* 197 */ SDLK_UNKNOWN,
-    /* 198 */ SDLK_UNKNOWN,
-    /* 199 */ SDLK_UNKNOWN,
-    /* 200 */ SDLK_UNKNOWN,
-    /* 201 */ SDLK_UNKNOWN,
-    /* 202 */ SDLK_UNKNOWN,
-    /* 203 */ SDLK_UNKNOWN,
-    /* 204 */ SDLK_UNKNOWN,
-    /* 205 */ SDLK_UNKNOWN,
-    /* 206 */ SDLK_UNKNOWN,
-    /* 207 */ SDLK_UNKNOWN,
-    /* 208 */ SDLK_UNKNOWN,
-    /* 209 */ SDLK_UNKNOWN,
-    /* 210 */ SDLK_UNKNOWN,
-    /* 211 */ SDLK_UNKNOWN,
-    /* 212 */ SDLK_UNKNOWN,
-    /* 213 */ SDLK_UNKNOWN,
-    /* 214 */ SDLK_UNKNOWN,
-    /* 215 */ SDLK_UNKNOWN,
-    /* 216 */ SDLK_UNKNOWN,
-    /* 217 */ SDLK_UNKNOWN,
-    /* 218 */ SDLK_UNKNOWN,
-    /* 219 */ SDLK_LEFTBRACKET,
-    /* 220 */ SDLK_BACKSLASH,
-    /* 221 */ SDLK_RIGHTBRACKET,
-    /* 222 */ SDLK_APOSTROPHE, /*FX, D3E legacy*/
+    /*   0, 0x00 */ SDLK_UNKNOWN,
+    /*   1, 0x01 */ SDLK_UNKNOWN,
+    /*   2, 0x02 */ SDLK_UNKNOWN,
+    /*   3, 0x03 */ SDLK_CANCEL,
+    /*   4, 0x04 */ SDLK_UNKNOWN,
+    /*   5, 0x05 */ SDLK_UNKNOWN,
+    /*   6, 0x06 */ SDLK_HELP,
+    /*   7, 0x07 */ SDLK_UNKNOWN,
+    /*   8, 0x08 */ SDLK_BACKSPACE,
+    /*   9, 0x09 */ SDLK_TAB,
+    /*  10, 0x0a */ SDLK_UNKNOWN,
+    /*  11, 0x0b */ SDLK_UNKNOWN,
+    /*  12, 0x0c */ SDLK_KP_EQUALS,
+    /*  13, 0x0d */ SDLK_RETURN,
+    /*  14, 0x0e */ SDLK_UNKNOWN,
+    /*  15, 0x0f */ SDLK_UNKNOWN,
+    /*  16, 0x10 */ SDLK_LSHIFT,
+    /*  17, 0x11 */ SDLK_LCTRL,
+    /*  18, 0x12 */ SDLK_LALT,
+    /*  19, 0x13 */ SDLK_PAUSE,
+    /*  20, 0x14 */ SDLK_CAPSLOCK,
+    /*  21, 0x15 */ SDLK_UNKNOWN,
+    /*  22, 0x16 */ SDLK_UNKNOWN,
+    /*  23, 0x17 */ SDLK_UNKNOWN,
+    /*  24, 0x18 */ SDLK_UNKNOWN,
+    /*  25, 0x19 */ SDLK_UNKNOWN,
+    /*  26, 0x1a */ SDLK_UNKNOWN,
+    /*  27, 0x1b */ SDLK_ESCAPE,
+    /*  28, 0x1c */ SDLK_UNKNOWN,
+    /*  29, 0x1d */ SDLK_UNKNOWN,
+    /*  30, 0x1e */ SDLK_UNKNOWN,
+    /*  31, 0x1f */ SDLK_UNKNOWN,
+    /*  32, 0x20 */ SDLK_SPACE,
+    /*  33, 0x21 */ SDLK_PAGEUP,
+    /*  34, 0x22 */ SDLK_PAGEDOWN,
+    /*  35, 0x23 */ SDLK_END,
+    /*  36, 0x24 */ SDLK_HOME,
+    /*  37, 0x25 */ SDLK_LEFT,
+    /*  38, 0x26 */ SDLK_UP,
+    /*  39, 0x27 */ SDLK_RIGHT,
+    /*  40, 0x28 */ SDLK_DOWN,
+    /*  41, 0x29 */ SDLK_UNKNOWN,
+    /*  42, 0x2a */ SDLK_UNKNOWN,
+    /*  43, 0x2b */ SDLK_UNKNOWN,
+    /*  44, 0x2c */ SDLK_UNKNOWN,
+    /*  45, 0x2d */ SDLK_INSERT,
+    /*  46, 0x2e */ SDLK_DELETE,
+    /*  47, 0x2f */ SDLK_UNKNOWN,
+    /*  48, 0x30 */ SDLK_0,
+    /*  49, 0x31 */ SDLK_1,
+    /*  50, 0x32 */ SDLK_2,
+    /*  51, 0x33 */ SDLK_3,
+    /*  52, 0x34 */ SDLK_4,
+    /*  53, 0x35 */ SDLK_5,
+    /*  54, 0x36 */ SDLK_6,
+    /*  55, 0x37 */ SDLK_7,
+    /*  56, 0x38 */ SDLK_8,
+    /*  57, 0x39 */ SDLK_9,
+    /*  58, 0x3a */ SDLK_UNKNOWN,
+    /*  59, 0x3b */ SDLK_SEMICOLON,
+    /*  60, 0x3c */ SDLK_BACKSLASH /*SDL_SCANCODE_NONUSBACKSLASH*/,
+    /*  61, 0x3d */ SDLK_EQUALS,
+    /*  62, 0x3e */ SDLK_UNKNOWN,
+    /*  63, 0x3f */ SDLK_MINUS,
+    /*  64, 0x40 */ SDLK_UNKNOWN,
+    /*  65, 0x41 */ SDLK_A,
+    /*  66, 0x42 */ SDLK_B,
+    /*  67, 0x43 */ SDLK_C,
+    /*  68, 0x44 */ SDLK_D,
+    /*  69, 0x45 */ SDLK_E,
+    /*  70, 0x46 */ SDLK_F,
+    /*  71, 0x47 */ SDLK_G,
+    /*  72, 0x48 */ SDLK_H,
+    /*  73, 0x49 */ SDLK_I,
+    /*  74, 0x4a */ SDLK_J,
+    /*  75, 0x4b */ SDLK_K,
+    /*  76, 0x4c */ SDLK_L,
+    /*  77, 0x4d */ SDLK_M,
+    /*  78, 0x4e */ SDLK_N,
+    /*  79, 0x4f */ SDLK_O,
+    /*  80, 0x50 */ SDLK_P,
+    /*  81, 0x51 */ SDLK_Q,
+    /*  82, 0x52 */ SDLK_R,
+    /*  83, 0x53 */ SDLK_S,
+    /*  84, 0x54 */ SDLK_T,
+    /*  85, 0x55 */ SDLK_U,
+    /*  86, 0x56 */ SDLK_V,
+    /*  87, 0x57 */ SDLK_W,
+    /*  88, 0x58 */ SDLK_X,
+    /*  89, 0x59 */ SDLK_Y,
+    /*  90, 0x5a */ SDLK_Z,
+    /*  91, 0x5b */ SDLK_LGUI,
+    /*  92, 0x5c */ SDLK_UNKNOWN,
+    /*  93, 0x5d */ SDLK_APPLICATION,
+    /*  94, 0x5e */ SDLK_UNKNOWN,
+    /*  95, 0x5f */ SDLK_UNKNOWN,
+    /*  96, 0x60 */ SDLK_0,         /* SDLK_KP_0 */
+    /*  97, 0x61 */ SDLK_1,         /* SDLK_KP_1 */
+    /*  98, 0x62 */ SDLK_2,         /* SDLK_KP_2 */
+    /*  99, 0x63 */ SDLK_3,         /* SDLK_KP_3 */
+    /* 100, 0x64 */ SDLK_4,         /* SDLK_KP_4 */
+    /* 101, 0x65 */ SDLK_5,         /* SDLK_KP_5 */
+    /* 102, 0x66 */ SDLK_6,         /* SDLK_KP_6 */
+    /* 103, 0x67 */ SDLK_7,         /* SDLK_KP_7 */
+    /* 104, 0x68 */ SDLK_8,         /* SDLK_KP_8 */
+    /* 105, 0x69 */ SDLK_9,         /* SDLK_KP_9 */
+    /* 106, 0x6a */ SDLK_KP_MULTIPLY,
+    /* 107, 0x6b */ SDLK_KP_PLUS,
+    /* 108, 0x6c */ SDLK_UNKNOWN,
+    /* 109, 0x6d */ SDLK_KP_MINUS,
+    /* 110, 0x6e */ SDLK_PERIOD,    /* SDLK_KP_PERIOD */
+    /* 111, 0x6f */ SDLK_KP_DIVIDE,
+    /* 112, 0x70 */ SDLK_F1,
+    /* 113, 0x71 */ SDLK_F2,
+    /* 114, 0x72 */ SDLK_F3,
+    /* 115, 0x73 */ SDLK_F4,
+    /* 116, 0x74 */ SDLK_F5,
+    /* 117, 0x75 */ SDLK_F6,
+    /* 118, 0x76 */ SDLK_F7,
+    /* 119, 0x77 */ SDLK_F8,
+    /* 120, 0x78 */ SDLK_F9,
+    /* 121, 0x79 */ SDLK_F10,
+    /* 122, 0x7a */ SDLK_F11,
+    /* 123, 0x7b */ SDLK_F12,
+    /* 124, 0x7c */ SDLK_F13,
+    /* 125, 0x7d */ SDLK_F14,
+    /* 126, 0x7e */ SDLK_F15,
+    /* 127, 0x7f */ SDLK_F16,
+    /* 128, 0x80 */ SDLK_F17,
+    /* 129, 0x81 */ SDLK_F18,
+    /* 130, 0x82 */ SDLK_F19,
+    /* 131, 0x83 */ SDLK_F20,
+    /* 132, 0x84 */ SDLK_F21,
+    /* 133, 0x85 */ SDLK_F22,
+    /* 134, 0x86 */ SDLK_F23,
+    /* 135, 0x87 */ SDLK_F24,
+    /* 136, 0x88 */ SDLK_UNKNOWN,
+    /* 137, 0x89 */ SDLK_UNKNOWN,
+    /* 138, 0x8a */ SDLK_UNKNOWN,
+    /* 139, 0x8b */ SDLK_UNKNOWN,
+    /* 140, 0x8c */ SDLK_UNKNOWN,
+    /* 141, 0x8d */ SDLK_UNKNOWN,
+    /* 142, 0x8e */ SDLK_UNKNOWN,
+    /* 143, 0x8f */ SDLK_UNKNOWN,
+    /* 144, 0x90 */ SDLK_NUMLOCKCLEAR,
+    /* 145, 0x91 */ SDLK_SCROLLLOCK,
+    /* 146, 0x92 */ SDLK_UNKNOWN,
+    /* 147, 0x93 */ SDLK_UNKNOWN,
+    /* 148, 0x94 */ SDLK_UNKNOWN,
+    /* 149, 0x95 */ SDLK_UNKNOWN,
+    /* 150, 0x96 */ SDLK_UNKNOWN,
+    /* 151, 0x97 */ SDLK_UNKNOWN,
+    /* 152, 0x98 */ SDLK_UNKNOWN,
+    /* 153, 0x99 */ SDLK_UNKNOWN,
+    /* 154, 0x9a */ SDLK_UNKNOWN,
+    /* 155, 0x9b */ SDLK_UNKNOWN,
+    /* 156, 0x9c */ SDLK_UNKNOWN,
+    /* 157, 0x9d */ SDLK_UNKNOWN,
+    /* 158, 0x9e */ SDLK_UNKNOWN,
+    /* 159, 0x9f */ SDLK_UNKNOWN,
+    /* 160, 0xa0 */ SDLK_GRAVE,
+    /* 161, 0xa1 */ SDLK_UNKNOWN,
+    /* 162, 0xa2 */ SDLK_UNKNOWN,
+    /* 163, 0xa3 */ SDLK_KP_HASH, /*KaiOS phone keypad*/
+    /* 164, 0xa4 */ SDLK_UNKNOWN,
+    /* 165, 0xa5 */ SDLK_UNKNOWN,
+    /* 166, 0xa6 */ SDLK_UNKNOWN,
+    /* 167, 0xa7 */ SDLK_UNKNOWN,
+    /* 168, 0xa8 */ SDLK_UNKNOWN,
+    /* 169, 0xa9 */ SDLK_UNKNOWN,
+    /* 170, 0xaa */ SDLK_KP_MULTIPLY, /*KaiOS phone keypad*/
+    /* 171, 0xab */ SDLK_RIGHTBRACKET,
+    /* 172, 0xac */ SDLK_UNKNOWN,
+    /* 173, 0xad */ SDLK_MINUS,      /*FX*/
+    /* 174, 0xae */ SDLK_VOLUMEDOWN, /*IE, Chrome*/
+    /* 175, 0xaf */ SDLK_VOLUMEUP,   /*IE, Chrome*/
+    /* 176, 0xb0 */ SDLK_MEDIA_NEXT_TRACK,  /*IE, Chrome*/
+    /* 177, 0xb1 */ SDLK_MEDIA_PREVIOUS_TRACK,  /*IE, Chrome*/
+    /* 178, 0xb2 */ SDLK_UNKNOWN,
+    /* 179, 0xb3 */ SDLK_MEDIA_PLAY, /*IE, Chrome*/
+    /* 180, 0xb4 */ SDLK_UNKNOWN,
+    /* 181, 0xb5 */ SDLK_UNKNOWN,
+    /* 182, 0xb6 */ SDLK_VOLUMEDOWN, /*FX*/
+    /* 183, 0xb7 */ SDLK_VOLUMEUP,   /*FX*/
+    /* 184, 0xb8 */ SDLK_UNKNOWN,
+    /* 185, 0xb9 */ SDLK_UNKNOWN,
+    /* 186, 0xba */ SDLK_SEMICOLON, /*IE, Chrome, D3E legacy*/
+    /* 187, 0xbb */ SDLK_EQUALS,    /*IE, Chrome, D3E legacy*/
+    /* 188, 0xbc */ SDLK_COMMA,
+    /* 189, 0xbd */ SDLK_MINUS, /*IE, Chrome, D3E legacy*/
+    /* 190, 0xbe */ SDLK_PERIOD,
+    /* 191, 0xbf */ SDLK_SLASH,
+    /* 192, 0xc0 */ SDLK_GRAVE, /*FX, D3E legacy (SDLK_APOSTROPHE in IE/Chrome)*/
+    /* 193, 0xc1 */ SDLK_UNKNOWN,
+    /* 194, 0xc2 */ SDLK_UNKNOWN,
+    /* 195, 0xc3 */ SDLK_UNKNOWN,
+    /* 196, 0xc4 */ SDLK_UNKNOWN,
+    /* 197, 0xc5 */ SDLK_UNKNOWN,
+    /* 198, 0xc6 */ SDLK_UNKNOWN,
+    /* 199, 0xc7 */ SDLK_UNKNOWN,
+    /* 200, 0xc8 */ SDLK_UNKNOWN,
+    /* 201, 0xc9 */ SDLK_UNKNOWN,
+    /* 202, 0xca */ SDLK_UNKNOWN,
+    /* 203, 0xcb */ SDLK_UNKNOWN,
+    /* 204, 0xcc */ SDLK_UNKNOWN,
+    /* 205, 0xcd */ SDLK_UNKNOWN,
+    /* 206, 0xce */ SDLK_UNKNOWN,
+    /* 207, 0xcf */ SDLK_UNKNOWN,
+    /* 208, 0xd0 */ SDLK_UNKNOWN,
+    /* 209, 0xd1 */ SDLK_UNKNOWN,
+    /* 210, 0xd2 */ SDLK_UNKNOWN,
+    /* 211, 0xd3 */ SDLK_UNKNOWN,
+    /* 212, 0xd4 */ SDLK_UNKNOWN,
+    /* 213, 0xd5 */ SDLK_UNKNOWN,
+    /* 214, 0xd6 */ SDLK_UNKNOWN,
+    /* 215, 0xd7 */ SDLK_UNKNOWN,
+    /* 216, 0xd8 */ SDLK_UNKNOWN,
+    /* 217, 0xd9 */ SDLK_UNKNOWN,
+    /* 218, 0xda */ SDLK_UNKNOWN,
+    /* 219, 0xdb */ SDLK_LEFTBRACKET,
+    /* 220, 0xdc */ SDLK_BACKSLASH,
+    /* 221, 0xdd */ SDLK_RIGHTBRACKET,
+    /* 222, 0xde */ SDLK_APOSTROPHE, /*FX, D3E legacy*/
 };
 
 /*
@@ -513,56 +513,6 @@ static SDL_Keycode Emscripten_MapKeyCode(const EmscriptenKeyboardEvent *keyEvent
                 default:
                     break;
                 }
-            } else if (keyEvent->location == DOM_KEY_LOCATION_NUMPAD) {
-                switch (keycode) {
-                case SDLK_0:
-                case SDLK_INSERT:
-                    keycode = SDLK_KP_0;
-                    break;
-                case SDLK_1:
-                case SDLK_END:
-                    keycode = SDLK_KP_1;
-                    break;
-                case SDLK_2:
-                case SDLK_DOWN:
-                    keycode = SDLK_KP_2;
-                    break;
-                case SDLK_3:
-                case SDLK_PAGEDOWN:
-                    keycode = SDLK_KP_3;
-                    break;
-                case SDLK_4:
-                case SDLK_LEFT:
-                    keycode = SDLK_KP_4;
-                    break;
-                case SDLK_5:
-                    keycode = SDLK_KP_5;
-                    break;
-                case SDLK_6:
-                case SDLK_RIGHT:
-                    keycode = SDLK_KP_6;
-                    break;
-                case SDLK_7:
-                case SDLK_HOME:
-                    keycode = SDLK_KP_7;
-                    break;
-                case SDLK_8:
-                case SDLK_UP:
-                    keycode = SDLK_KP_8;
-                    break;
-                case SDLK_9:
-                case SDLK_PAGEUP:
-                    keycode = SDLK_KP_9;
-                    break;
-                case SDLK_RETURN:
-                    keycode = SDLK_KP_ENTER;
-                    break;
-                case SDLK_DELETE:
-                    keycode = SDLK_KP_PERIOD;
-                    break;
-                default:
-                    break;
-                }
             }
         }
     }
diff --git a/src/video/wayland/SDL_waylandevents.c b/src/video/wayland/SDL_waylandevents.c
index 68b65f92aa78e..4a6f4f04c45a6 100644
--- a/src/video/wayland/SDL_waylandevents.c
+++ b/src/video/wayland/SDL_waylandevents.c
@@ -1109,7 +1109,7 @@ static void Wayland_keymap_iter(struct xkb_keymap *keymap, xkb_keycode_t key, vo
 
             /* Note: The default SDL scancode table sets this to right alt instead of AltGr/Mode, so handle it separately. */
             if (syms[0] != XKB_KEY_ISO_Level3_Shift) {
-                keycode = SDL_GetDefaultKeyFromScancode(sc, SDL_KMOD_NONE);
+                keycode = SDL_GetDefaultKeyFromScancode(sc, sdlKeymap->modstate);
             } else {
                 keycode = SDLK_MODE;
             }
diff --git a/src/video

(Patch may be truncated, please check the link at the top of this post.)