[Commits] SDL: Fixed bug 3188 - AZERTY keyboard support broken and inconsi...

libsdl.org revision control commits-owner at libsdl.org
Sat Aug 12 15:41:07 PDT 2017


details:   https://hg.libsdl.org/SDL/rev/27eb9a10002c
changeset: 11247:27eb9a10002c
user:      Sam Lantinga <slouken at libsdl.org>
date:      Sat Aug 12 15:41:03 2017 -0700
description:
Fixed bug 3188 - AZERTY keyboard support broken and inconsistent

Daniel Gibson

AZERTY keyboard layouts (which are the default layouts in France and Belgium) don't have the number keys (1, 2, ..., 9, 0) in the first row of keys, but ², &, é", ', (, -, è_, çà), = (with small differences between the France and Belgian variants). Numbers are reached via shift.

On Linux and OSX, SDL seems to use the corresponding ISO 8859-1 codes (231 for ç232 for ètc) as SDL_Keycode (but no SDK_* constants exists for those values!), while on Windows SDL seems to map those keys to SDLK_1, SDLK_2 etc, like you'd get on QWERTY.
I don't know how other platforms behave.

So we have two problems:
1. At least on Linux and OSX invalid/undefined SDL_Keycodes are returned
2. Different platforms behave differently (Windows vs Linux/OSX)

It's unclear what behavior is desired: Should SDL_* constants for those keys be introduced (and Windows behavior changed accordingly)?
Or should all platforms behave like Windows here and use the existing SDLK_1, ..., SDLK_0 keycodes?

This bug on the mailing list:
https://forums.libsdl.org/viewtopic.php?t=11555 (my post about Linux/Windows)
https://forums.libsdl.org/viewtopic.php?t=11573 (Tim Walters discovered the same problem on OSX about 1.5 weeks later).

diffstat:

 src/events/SDL_keyboard.c |  10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diffs (26 lines):

diff -r 1667e6dafc85 -r 27eb9a10002c src/events/SDL_keyboard.c
--- a/src/events/SDL_keyboard.c	Sat Aug 12 15:21:26 2017 -0700
+++ b/src/events/SDL_keyboard.c	Sat Aug 12 15:41:03 2017 -0700
@@ -594,12 +594,22 @@
 SDL_SetKeymap(int start, SDL_Keycode * keys, int length)
 {
     SDL_Keyboard *keyboard = &SDL_keyboard;
+    SDL_Scancode scancode;
 
     if (start < 0 || start + length > SDL_NUM_SCANCODES) {
         return;
     }
 
     SDL_memcpy(&keyboard->keymap[start], keys, sizeof(*keys) * length);
+
+    /* The number key scancodes always map to the number key keycodes.
+     * On AZERTY layouts these technically are symbols, but users (and games)
+     * always think of them and view them in UI as number keys.
+     */
+    keyboard->keymap[SDL_SCANCODE_0] = SDLK_0;
+    for (scancode = SDL_SCANCODE_1; scancode <= SDL_SCANCODE_9; ++scancode) {
+        keyboard->keymap[scancode] = SDLK_1 + (scancode - SDL_SCANCODE_1);
+    }
 }
 
 void


More information about the commits mailing list