From fb3df3a18d8f8e7f9a948d2dbca60398b97ea27c Mon Sep 17 00:00:00 2001 From: Daid Date: Thu, 9 Apr 2020 15:01:41 +0100 Subject: [PATCH] emscripten: Fix the reported keys for the numpad. See https://github.com/emscripten-ports/SDL2/issues/94 --- src/video/emscripten/SDL_emscriptenevents.c | 51 ++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/src/video/emscripten/SDL_emscriptenevents.c b/src/video/emscripten/SDL_emscriptenevents.c index 6376580ea..fa5bb163e 100644 --- a/src/video/emscripten/SDL_emscriptenevents.c +++ b/src/video/emscripten/SDL_emscriptenevents.c @@ -55,7 +55,7 @@ static const SDL_Scancode emscripten_scancode_table[] = { /* 9 */ SDL_SCANCODE_TAB, /* 10 */ SDL_SCANCODE_UNKNOWN, /* 11 */ SDL_SCANCODE_UNKNOWN, - /* 12 */ SDL_SCANCODE_UNKNOWN, + /* 12 */ SDL_SCANCODE_KP_5, /* 13 */ SDL_SCANCODE_RETURN, /* 14 */ SDL_SCANCODE_UNKNOWN, /* 15 */ SDL_SCANCODE_UNKNOWN, @@ -513,6 +513,55 @@ Emscripten_HandleKey(int eventType, const EmscriptenKeyboardEvent *keyEvent, voi break; } } + else if (keyEvent->location == DOM_KEY_LOCATION_NUMPAD) { + switch (scancode) { + case SDL_SCANCODE_0: + case SDL_SCANCODE_INSERT: + scancode = SDL_SCANCODE_KP_0; + break; + case SDL_SCANCODE_1: + case SDL_SCANCODE_END: + scancode = SDL_SCANCODE_KP_1; + break; + case SDL_SCANCODE_2: + case SDL_SCANCODE_DOWN: + scancode = SDL_SCANCODE_KP_2; + break; + case SDL_SCANCODE_3: + case SDL_SCANCODE_PAGEDOWN: + scancode = SDL_SCANCODE_KP_3; + break; + case SDL_SCANCODE_4: + case SDL_SCANCODE_LEFT: + scancode = SDL_SCANCODE_KP_4; + break; + case SDL_SCANCODE_5: + scancode = SDL_SCANCODE_KP_5; + break; + case SDL_SCANCODE_6: + case SDL_SCANCODE_RIGHT: + scancode = SDL_SCANCODE_KP_6; + break; + case SDL_SCANCODE_7: + case SDL_SCANCODE_HOME: + scancode = SDL_SCANCODE_KP_7; + break; + case SDL_SCANCODE_8: + case SDL_SCANCODE_UP: + scancode = SDL_SCANCODE_KP_8; + break; + case SDL_SCANCODE_9: + case SDL_SCANCODE_PAGEUP: + scancode = SDL_SCANCODE_KP_9; + break; + case SDL_SCANCODE_RETURN: + scancode = SDL_SCANCODE_KP_ENTER; + break; + case SDL_SCANCODE_DELETE: + scancode = SDL_SCANCODE_KP_PERIOD; + break; + } + } SDL_SendKeyboardKey(eventType == EMSCRIPTEN_EVENT_KEYDOWN ? SDL_PRESSED : SDL_RELEASED, scancode); } }