From c5ad45368ad49baaa711ea2e7bd0050f40a68317 Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Sun, 22 Nov 2015 23:21:30 +0100 Subject: [PATCH] Workaround to better support AZERTY keyboards MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The first row of AZERTY-Keyboards (used in France and Belgium) doesn't have numbers as keys but ², &, é, ", ', (, -, è, _, ç, à, ), = (with small differences between France and Belgium). For some of those keys we don't have keycodes - and neither does SDL2. See also https://bugzilla.libsdl.org/show_bug.cgi?id=3188 As a workaround, just map those keys to 1, 2, ..., 9, 0 anyway, as those are keys Quake2 already knows (and those chars are printed on the keys too, for typing they're reachable via shift). This workaround only works for SDL2, as SDL1.2 doesn't have Scancodes which we need to identify the keys. This should obsolete one part of pull request #135 --- neo/sys/events.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/neo/sys/events.cpp b/neo/sys/events.cpp index 7fb1ef7a..288d6c0b 100644 --- a/neo/sys/events.cpp +++ b/neo/sys/events.cpp @@ -484,8 +484,8 @@ sysEvent_t Sys_GetEvent() { // fall through case SDL_KEYUP: - key = mapkey(ev.key.keysym.sym); #if !SDL_VERSION_ATLEAST(2, 0, 0) + key = mapkey(ev.key.keysym.sym); if (!key) { unsigned char c; // check if its an unmapped console key @@ -500,6 +500,27 @@ sysEvent_t Sys_GetEvent() { } } #else + { + // workaround for AZERTY-keyboards, which don't have 1, 2, ..., 9, 0 in first row: + // always map those physical keys (scancodes) to those keycodes anyway + // see also https://bugzilla.libsdl.org/show_bug.cgi?id=3188 + SDL_Scancode sc = ev.key.keysym.scancode; + if(sc == SDL_SCANCODE_0) + { + key = '0'; + } + else if(sc >= SDL_SCANCODE_1 && sc <= SDL_SCANCODE_9) + { + // note that the SDL_SCANCODEs are SDL_SCANCODE_1, _2, ..., _9, SDL_SCANCODE_0 + // while in ASCII it's '0', '1', ..., '9' => handle 0 and 1-9 separately + // (doom3 uses the ASCII values for those keys) + key = '1' + (sc - SDL_SCANCODE_1); + } + else + { + key = mapkey(ev.key.keysym.sym); + } + if(!key) { if (ev.key.keysym.scancode == SDL_SCANCODE_GRAVE) { // TODO: always do this check? key = Sys_GetConsoleKey(true); @@ -510,7 +531,7 @@ sysEvent_t Sys_GetEvent() { continue; // handle next event } } - + } #endif res.evType = SE_KEY;