Skip to content

Commit

Permalink
Restore default behavior for keypad keycodes
Browse files Browse the repository at this point in the history
Added a hint to translate numpad keycodes into their non-numpad versions based on the NumLock state
  • Loading branch information
slouken committed Jul 3, 2024
1 parent bafd04e commit 366871f
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 101 deletions.
1 change: 1 addition & 0 deletions include/SDL3/SDL_hints.h
Original file line number Diff line number Diff line change
Expand Up @@ -2000,6 +2000,7 @@ extern "C" {
* in events:
*
* - "none": Keycode options are cleared, this overrides other options.
* - "hide_numpad": The numpad keysyms will be translated into their non-numpad versions based on the current NumLock state. For example, SDLK_KP_4 would become SDLK_4 if SDL_KMOD_NUM is set in the event modifiers, and SDLK_LEFT if it is unset.
* - "french_numbers": The number row on French keyboards is inverted, so
* pressing the 1 key would yield the keycode SDLK_1, or '1', instead of
* SDLK_AMPERSAND, or '&'
Expand Down
41 changes: 41 additions & 0 deletions include/SDL3/SDL_keycode.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,25 @@ 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) */
Expand All @@ -180,6 +197,8 @@ 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) */
Expand All @@ -198,18 +217,40 @@ 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) */
#define SDLK_KP_MEMADD 0x400000d3u /* SDL_SCANCODE_TO_KEYCODE(SDL_SCANCODE_KP_MEMADD) */
#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) */
Expand Down
130 changes: 116 additions & 14 deletions src/events/SDL_keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@

#define KEYBOARD_SOURCE_MASK (KEYBOARD_HARDWARE | KEYBOARD_AUTORELEASE)

#define KEYCODE_OPTION_FRENCH_NUMBERS 0x01
#define KEYCODE_OPTION_LATIN_LETTERS 0x02
#define KEYCODE_OPTION_HIDE_NUMPAD 0x01
#define KEYCODE_OPTION_FRENCH_NUMBERS 0x02
#define KEYCODE_OPTION_LATIN_LETTERS 0x04
#define DEFAULT_KEYCODE_OPTIONS (KEYCODE_OPTION_FRENCH_NUMBERS)

typedef struct SDL_KeyboardInstance
Expand Down Expand Up @@ -74,6 +75,9 @@ static void SDLCALL SDL_KeycodeOptionsChanged(void *userdata, const char *name,
if (hint && *hint) {
keyboard->keycode_options = 0;
if (!SDL_strstr(hint, "none")) {
if (SDL_strstr(hint, "hide_numpad")) {
keyboard->keycode_options |= KEYCODE_OPTION_HIDE_NUMPAD;
}
if (SDL_strstr(hint, "french_numbers")) {
keyboard->keycode_options |= KEYCODE_OPTION_FRENCH_NUMBERS;
}
Expand Down Expand Up @@ -330,31 +334,129 @@ int SDL_SetKeyboardFocus(SDL_Window *window)
return 0;
}

static SDL_Keycode SDL_ConvertNumpadKeycode(SDL_Keycode keycode, SDL_bool numlock)
{
switch (keycode) {
case SDLK_KP_DIVIDE:
return SDLK_SLASH;
case SDLK_KP_MULTIPLY:
return SDLK_ASTERISK;
case SDLK_KP_MINUS:
return SDLK_MINUS;
case SDLK_KP_PLUS:
return SDLK_PLUS;
case SDLK_KP_ENTER:
return SDLK_RETURN;
case SDLK_KP_1:
return numlock ? SDLK_1 : SDLK_END;
case SDLK_KP_2:
return numlock ? SDLK_2 : SDLK_DOWN;
case SDLK_KP_3:
return numlock ? SDLK_3 : SDLK_PAGEDOWN;
case SDLK_KP_4:
return numlock ? SDLK_4 : SDLK_LEFT;
case SDLK_KP_5:
return numlock ? SDLK_5 : SDLK_CLEAR;
case SDLK_KP_6:
return numlock ? SDLK_6 : SDLK_RIGHT;
case SDLK_KP_7:
return numlock ? SDLK_7 : SDLK_HOME;
case SDLK_KP_8:
return numlock ? SDLK_8 : SDLK_UP;
case SDLK_KP_9:
return numlock ? SDLK_9 : SDLK_PAGEUP;
case SDLK_KP_0:
return numlock ? SDLK_0 : SDLK_INSERT;
case SDLK_KP_PERIOD:
return numlock ? SDLK_PERIOD : SDLK_DELETE;
case SDLK_KP_EQUALS:
return SDLK_EQUALS;
case SDLK_KP_COMMA:
return SDLK_COMMA;
case SDLK_KP_EQUALSAS400:
return SDLK_EQUALS;
case SDLK_KP_LEFTPAREN:
return SDLK_LEFTPAREN;
case SDLK_KP_RIGHTPAREN:
return SDLK_RIGHTPAREN;
case SDLK_KP_LEFTBRACE:
return SDLK_LEFTBRACE;
case SDLK_KP_RIGHTBRACE:
return SDLK_RIGHTBRACE;
case SDLK_KP_TAB:
return SDLK_TAB;
case SDLK_KP_BACKSPACE:
return SDLK_BACKSPACE;
case SDLK_KP_A:
return SDLK_A;
case SDLK_KP_B:
return SDLK_B;
case SDLK_KP_C:
return SDLK_C;
case SDLK_KP_D:
return SDLK_D;
case SDLK_KP_E:
return SDLK_E;
case SDLK_KP_F:
return SDLK_F;
case SDLK_KP_PERCENT:
return SDLK_PERCENT;
case SDLK_KP_LESS:
return SDLK_LESS;
case SDLK_KP_GREATER:
return SDLK_GREATER;
case SDLK_KP_AMPERSAND:
return SDLK_AMPERSAND;
case SDLK_KP_COLON:
return SDLK_COLON;
case SDLK_KP_HASH:
return SDLK_HASH;
case SDLK_KP_SPACE:
return SDLK_SPACE;
case SDLK_KP_AT:
return SDLK_AT;
case SDLK_KP_EXCLAM:
return SDLK_EXCLAIM;
case SDLK_KP_PLUSMINUS:
return SDLK_PLUSMINUS;
default:
return keycode;
}
}

static SDL_Keycode SDL_GetEventKeycode(SDL_Keyboard *keyboard, SDL_Scancode scancode, SDL_Keymod modstate)
{
SDL_bool shifted = (modstate & SDL_KMOD_SHIFT) != 0;
SDL_bool numlock = (modstate & SDL_KMOD_NUM) != 0;
SDL_Keycode keycode;

// 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)) {
return SDL_GetDefaultKeyFromScancode(scancode, modstate);
}
}
// We won't be applying any modifiers by default
modstate = SDL_KMOD_NONE;

if (scancode >= SDL_SCANCODE_1 && scancode <= SDL_SCANCODE_0) {
if (keyboard->french_numbers && (keyboard->keycode_options & KEYCODE_OPTION_FRENCH_NUMBERS)) {
// Invert the shift state to generate the correct keycode
if ((keyboard->keycode_options & KEYCODE_OPTION_LATIN_LETTERS) &&
keyboard->non_latin_letters &&
scancode >= SDL_SCANCODE_A && scancode <= SDL_SCANCODE_Z) {
keycode = SDL_GetDefaultKeyFromScancode(scancode, modstate);
} else {
if ((keyboard->keycode_options & KEYCODE_OPTION_FRENCH_NUMBERS) &&
keyboard->french_numbers &&
(scancode >= SDL_SCANCODE_1 && scancode <= SDL_SCANCODE_0)) {
// Invert the shift state to generate the expected keycode
if (shifted) {
modstate &= ~SDL_KMOD_SHIFT;
} else {
modstate |= SDL_KMOD_SHIFT;
}
}

keycode = SDL_GetKeyFromScancode(scancode, modstate);
}

if (keyboard->keycode_options & KEYCODE_OPTION_HIDE_NUMPAD) {
keycode = SDL_ConvertNumpadKeycode(keycode, numlock);
}

return SDL_GetKeyFromScancode(scancode, modstate);
return keycode;
}

static int SDL_SendKeyboardKeyInternal(Uint64 timestamp, Uint32 flags, SDL_KeyboardID keyboardID, int rawcode, SDL_Scancode scancode, Uint8 state)
Expand Down
89 changes: 3 additions & 86 deletions src/events/SDL_keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,94 +238,11 @@ SDL_Keycode SDL_GetDefaultKeyFromScancode(SDL_Scancode scancode, SDL_Keymod mods
}
}

switch (scancode) {
case SDL_SCANCODE_DELETE:
if (scancode == 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)
Expand Down
2 changes: 1 addition & 1 deletion src/video/emscripten/SDL_emscriptenevents.c
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ static EM_BOOL Emscripten_HandleKey(int eventType, const EmscriptenKeyboardEvent
}
}

if (SDL_utf8strlen(keyEvent->key) == 1) {
if (keyEvent->location == 0 && SDL_utf8strlen(keyEvent->key) == 1) {
const char *key = keyEvent->key;
keycode = SDL_StepUTF8(&key, NULL);
if (keycode == SDL_INVALID_UNICODE_CODEPOINT) {
Expand Down

0 comments on commit 366871f

Please sign in to comment.