[Commits] SDL: Emscripten: Prevent default on arrow keys

libsdl.org revision control commits-owner at libsdl.org
Wed May 24 06:06:50 PDT 2017


details:   https://hg.libsdl.org/SDL/rev/2215b66794ba
changeset: 11025:2215b66794ba
user:      Charlie Birks <admin at daftgames.net>
date:      Wed May 24 14:04:39 2017 +0100
description:
Emscripten: Prevent default on arrow keys

diffstat:

 src/video/emscripten/SDL_emscriptenevents.c |  9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diffs (19 lines):

diff -r 32026cc5015a -r 2215b66794ba src/video/emscripten/SDL_emscriptenevents.c
--- a/src/video/emscripten/SDL_emscriptenevents.c	Wed May 24 14:04:25 2017 +0100
+++ b/src/video/emscripten/SDL_emscriptenevents.c	Wed May 24 14:04:39 2017 +0100
@@ -522,7 +522,14 @@
     /* 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;


More information about the commits mailing list