emscripten: Fix the reported keys for the numpad. See https://github.com/emscripten-ports/SDL2/issues/94
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
diff --git a/src/video/emscripten/SDL_emscriptenevents.c b/src/video/emscripten/SDL_emscriptenevents.c
index 6376580..fa5bb16 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);
}
}