Skip to content

Commit

Permalink
Emscripten: Prevent default on arrow keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Daft-Freak committed May 24, 2017
1 parent f839b20 commit 126e5a1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/video/emscripten/SDL_emscriptenevents.c
Expand Up @@ -522,7 +522,14 @@ Emscripten_HandleKey(int eventType, const EmscriptenKeyboardEvent *keyEvent, voi
/* if TEXTINPUT events are enabled we can't prevent keydown or we won't get keypress
* we need to ALWAYS prevent backspace and tab otherwise chrome takes action and does bad navigation UX
*/
if (eventType == EMSCRIPTEN_EVENT_KEYDOWN && SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE && keyEvent->keyCode != 8 /* backspace */ && keyEvent->keyCode != 9 /* tab */)
SDL_bool is_nav_key = keyEvent->keyCode == 8 /* backspace */ ||
keyEvent->keyCode == 9 /* tab */ ||
keyEvent->keyCode == 37 /* left */ ||
keyEvent->keyCode == 38 /* up */ ||
keyEvent->keyCode == 39 /* right */ ||
keyEvent->keyCode == 40 /* down */;

if (eventType == EMSCRIPTEN_EVENT_KEYDOWN && SDL_GetEventState(SDL_TEXTINPUT) == SDL_ENABLE && !is_nav_key)
prevent_default = SDL_FALSE;

return prevent_default;
Expand Down

0 comments on commit 126e5a1

Please sign in to comment.