Improved fix for bug 2096 - Mapping from scancode to keycode doesn't work for remapped modifier keys
authorSam Lantinga
Thu, 28 May 2015 19:06:07 -0700
changeset 96820265666d0238
parent 9681 c2e49a5b4928
child 9683 aa4e4768c6c1
Improved fix for bug 2096 - Mapping from scancode to keycode doesn't work for remapped modifier keys

Zack Middleton

The change to the keymap to use SDL_SCANCODE_TO_KEYCODE in SDL_x11keyboard.c causes all SDL scancodes without a Usc4 character to be XOR'd with SDLK_SCANCODE_MASK, but not all key code are suppose to be (as seen in include/SDL_keycodes.h). SDLK_BACKSPACE is not 0x4000002A.

I think the full list of keys affected are return, escape, backspace, tab, and delete.
src/video/x11/SDL_x11keyboard.c
     1.1 --- a/src/video/x11/SDL_x11keyboard.c	Thu May 28 18:57:57 2015 -0700
     1.2 +++ b/src/video/x11/SDL_x11keyboard.c	Thu May 28 19:06:07 2015 -0700
     1.3 @@ -316,7 +316,28 @@
     1.4          if (key) {
     1.5              keymap[scancode] = key;
     1.6          } else {
     1.7 -            keymap[scancode] = SDL_SCANCODE_TO_KEYCODE(X11_KeyCodeToSDLScancode(data->display, (KeyCode)i));
     1.8 +            SDL_Scancode keyScancode = X11_KeyCodeToSDLScancode(data->display, (KeyCode)i);
     1.9 +
    1.10 +            switch (keyScancode) {
    1.11 +                case SDL_SCANCODE_RETURN:
    1.12 +                    keymap[scancode] = SDLK_RETURN;
    1.13 +                    break;
    1.14 +                case SDL_SCANCODE_ESCAPE:
    1.15 +                    keymap[scancode] = SDLK_ESCAPE;
    1.16 +                    break;
    1.17 +                case SDL_SCANCODE_BACKSPACE:
    1.18 +                    keymap[scancode] = SDLK_BACKSPACE;
    1.19 +                    break;
    1.20 +                case SDL_SCANCODE_TAB:
    1.21 +                    keymap[scancode] = SDLK_TAB;
    1.22 +                    break;
    1.23 +                case SDL_SCANCODE_DELETE:
    1.24 +                    keymap[scancode] = SDLK_DELETE;
    1.25 +                    break;
    1.26 +                default:
    1.27 +                    keymap[scancode] = SDL_SCANCODE_TO_KEYCODE(keyScancode);
    1.28 +                    break;
    1.29 +            }
    1.30          }
    1.31      }
    1.32      SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES);