Fixed a number of missing keys in the X11 keyboard mapping.
authorSam Lantinga <slouken@libsdl.org>
Tue, 06 Aug 2013 18:19:34 -0700
changeset 75805a924aac594c
parent 7579 efb0c78d4a48
child 7581 c6b4fab28e00
Fixed a number of missing keys in the X11 keyboard mapping.
src/events/scancodes_xfree86.h
src/video/x11/SDL_x11keyboard.c
     1.1 --- a/src/events/scancodes_xfree86.h	Tue Aug 06 12:56:47 2013 -0700
     1.2 +++ b/src/events/scancodes_xfree86.h	Tue Aug 06 18:19:34 2013 -0700
     1.3 @@ -141,8 +141,8 @@
     1.4      /*  112 */  SDL_SCANCODE_F15,
     1.5      /*  113 */  SDL_SCANCODE_F16,
     1.6      /*  114 */  SDL_SCANCODE_F17,
     1.7 -    /*  115 */	SDL_SCANCODE_UNKNOWN,
     1.8 -    /*	116 */  SDL_SCANCODE_UNKNOWN, /* is translated to XK_ISO_Level3_Shift by my X server, but I have no keyboard that generates this code, so I don't know what the correct SDL_SCANCODE_* for it is */
     1.9 +    /*  115 */  SDL_SCANCODE_UNKNOWN,
    1.10 +    /*  116 */  SDL_SCANCODE_UNKNOWN, /* is translated to XK_ISO_Level3_Shift by my X server, but I have no keyboard that generates this code, so I don't know what the correct SDL_SCANCODE_* for it is */
    1.11      /*  117 */  SDL_SCANCODE_UNKNOWN,
    1.12      /*  118 */  SDL_SCANCODE_KP_EQUALS,
    1.13      /*  119 */  SDL_SCANCODE_UNKNOWN,
    1.14 @@ -298,7 +298,7 @@
    1.15      /* 118 */   SDL_SCANCODE_UNKNOWN,   /* plusminus */
    1.16      /* 119 */   SDL_SCANCODE_PAUSE,
    1.17      /* 120 */   SDL_SCANCODE_UNKNOWN,   /* XF86LaunchA */
    1.18 -    /* 121 */   SDL_SCANCODE_UNKNOWN,	/* KP_Decimal */
    1.19 +    /* 121 */   SDL_SCANCODE_UNKNOWN,   /* KP_Decimal */
    1.20      /* 122 */   SDL_SCANCODE_UNKNOWN,   /* Hangul */
    1.21      /* 123 */   SDL_SCANCODE_UNKNOWN,   /* Hangul_Hanja */
    1.22      /* 124 */   SDL_SCANCODE_UNKNOWN,
    1.23 @@ -325,15 +325,15 @@
    1.24      /* 145 */   SDL_SCANCODE_UNKNOWN,   /* XF86Send */
    1.25      /* 146 */   SDL_SCANCODE_UNKNOWN,
    1.26      /* 147 */   SDL_SCANCODE_UNKNOWN,   /* XF86Xfer */
    1.27 -    /* 148 */   SDL_SCANCODE_UNKNOWN,   /* XF86Launch1 */
    1.28 -    /* 149 */   SDL_SCANCODE_UNKNOWN,   /* XF86Launch2 */
    1.29 +    /* 148 */   SDL_SCANCODE_APP1,      /* XF86Launch1 */
    1.30 +    /* 149 */   SDL_SCANCODE_APP2,      /* XF86Launch2 */
    1.31      /* 150 */   SDL_SCANCODE_WWW,
    1.32      /* 151 */   SDL_SCANCODE_UNKNOWN,   /* XF86DOS */
    1.33      /* 152 */   SDL_SCANCODE_UNKNOWN,   /* XF86ScreenSaver */
    1.34      /* 153 */   SDL_SCANCODE_UNKNOWN,
    1.35      /* 154 */   SDL_SCANCODE_UNKNOWN,   /* XF86RotateWindows */
    1.36      /* 155 */   SDL_SCANCODE_MAIL,
    1.37 -    /* 156 */   SDL_SCANCODE_UNKNOWN,   /* XF86Favorites */
    1.38 +    /* 156 */   SDL_SCANCODE_AC_BOOKMARKS,   /* XF86Favorites */
    1.39      /* 157 */   SDL_SCANCODE_COMPUTER,
    1.40      /* 158 */   SDL_SCANCODE_AC_BACK,
    1.41      /* 159 */   SDL_SCANCODE_AC_FORWARD,
    1.42 @@ -348,7 +348,7 @@
    1.43      /* 168 */   SDL_SCANCODE_UNKNOWN,   /* XF86AudioRewind */
    1.44      /* 169 */   SDL_SCANCODE_UNKNOWN,   /* XF86Phone */
    1.45      /* 170 */   SDL_SCANCODE_UNKNOWN,
    1.46 -    /* 171 */   SDL_SCANCODE_UNKNOWN,   /* XF86Tools */
    1.47 +    /* 171 */   SDL_SCANCODE_F13,       /* XF86Tools */
    1.48      /* 172 */   SDL_SCANCODE_AC_HOME,
    1.49      /* 173 */   SDL_SCANCODE_AC_REFRESH,
    1.50      /* 174 */   SDL_SCANCODE_UNKNOWN,   /* XF86Close */
    1.51 @@ -360,13 +360,13 @@
    1.52      /* 180 */   SDL_SCANCODE_UNKNOWN,   /* parenright */
    1.53      /* 181 */   SDL_SCANCODE_UNKNOWN,   /* XF86New */
    1.54      /* 182 */   SDL_SCANCODE_AGAIN,
    1.55 -    /* 183 */   SDL_SCANCODE_UNKNOWN,   /* XF86Tools */
    1.56 -    /* 184 */   SDL_SCANCODE_UNKNOWN,   /* XF86Launch5 */
    1.57 -    /* 185 */   SDL_SCANCODE_UNKNOWN,   /* XF86MenuKB */
    1.58 -    /* 186 */   SDL_SCANCODE_UNKNOWN,
    1.59 -    /* 187 */   SDL_SCANCODE_UNKNOWN,
    1.60 -    /* 188 */   SDL_SCANCODE_UNKNOWN,
    1.61 -    /* 189 */   SDL_SCANCODE_UNKNOWN,
    1.62 +    /* 183 */   SDL_SCANCODE_F13,       /* XF86Tools */
    1.63 +    /* 184 */   SDL_SCANCODE_F14,       /* XF86Launch5 */
    1.64 +    /* 185 */   SDL_SCANCODE_F15,       /* XF86Launch6 */
    1.65 +    /* 186 */   SDL_SCANCODE_F16,       /* XF86Launch7 */
    1.66 +    /* 187 */   SDL_SCANCODE_F17,       /* XF86Launch8 */
    1.67 +    /* 188 */   SDL_SCANCODE_F18,       /* XF86Launch9 */
    1.68 +    /* 189 */   SDL_SCANCODE_F19,       /* null keysym */
    1.69      /* 190 */   SDL_SCANCODE_UNKNOWN,
    1.70      /* 191 */   SDL_SCANCODE_UNKNOWN,
    1.71      /* 192 */   SDL_SCANCODE_UNKNOWN,   /* XF86TouchpadToggle */
     2.1 --- a/src/video/x11/SDL_x11keyboard.c	Tue Aug 06 12:56:47 2013 -0700
     2.2 +++ b/src/video/x11/SDL_x11keyboard.c	Tue Aug 06 18:19:34 2013 -0700
     2.3 @@ -35,102 +35,102 @@
     2.4  /* *INDENT-OFF* */
     2.5  static const struct {
     2.6      KeySym keysym;
     2.7 -    SDL_Keycode sdlkey;
     2.8 -} KeySymToSDLKey[] = {
     2.9 -    { XK_Return, SDLK_RETURN },
    2.10 -    { XK_Escape, SDLK_ESCAPE },
    2.11 -    { XK_BackSpace, SDLK_BACKSPACE },
    2.12 -    { XK_Tab, SDLK_TAB },
    2.13 -    { XK_Caps_Lock, SDLK_CAPSLOCK },
    2.14 -    { XK_F1, SDLK_F1 },
    2.15 -    { XK_F2, SDLK_F2 },
    2.16 -    { XK_F3, SDLK_F3 },
    2.17 -    { XK_F4, SDLK_F4 },
    2.18 -    { XK_F5, SDLK_F5 },
    2.19 -    { XK_F6, SDLK_F6 },
    2.20 -    { XK_F7, SDLK_F7 },
    2.21 -    { XK_F8, SDLK_F8 },
    2.22 -    { XK_F9, SDLK_F9 },
    2.23 -    { XK_F10, SDLK_F10 },
    2.24 -    { XK_F11, SDLK_F11 },
    2.25 -    { XK_F12, SDLK_F12 },
    2.26 -    { XK_Print, SDLK_PRINTSCREEN },
    2.27 -    { XK_Scroll_Lock, SDLK_SCROLLLOCK },
    2.28 -    { XK_Pause, SDLK_PAUSE },
    2.29 -    { XK_Insert, SDLK_INSERT },
    2.30 -    { XK_Home, SDLK_HOME },
    2.31 -    { XK_Prior, SDLK_PAGEUP },
    2.32 -    { XK_Delete, SDLK_DELETE },
    2.33 -    { XK_End, SDLK_END },
    2.34 -    { XK_Next, SDLK_PAGEDOWN },
    2.35 -    { XK_Right, SDLK_RIGHT },
    2.36 -    { XK_Left, SDLK_LEFT },
    2.37 -    { XK_Down, SDLK_DOWN },
    2.38 -    { XK_Up, SDLK_UP },
    2.39 -    { XK_Num_Lock, SDLK_NUMLOCKCLEAR },
    2.40 -    { XK_KP_Divide, SDLK_KP_DIVIDE },
    2.41 -    { XK_KP_Multiply, SDLK_KP_MULTIPLY },
    2.42 -    { XK_KP_Subtract, SDLK_KP_MINUS },
    2.43 -    { XK_KP_Add, SDLK_KP_PLUS },
    2.44 -    { XK_KP_Enter, SDLK_KP_ENTER },
    2.45 -    { XK_KP_Delete, SDLK_KP_PERIOD },
    2.46 -    { XK_KP_End, SDLK_KP_1 },
    2.47 -    { XK_KP_Down, SDLK_KP_2 },
    2.48 -    { XK_KP_Next, SDLK_KP_3 },
    2.49 -    { XK_KP_Left, SDLK_KP_4 },
    2.50 -    { XK_KP_Begin, SDLK_KP_5 },
    2.51 -    { XK_KP_Right, SDLK_KP_6 },
    2.52 -    { XK_KP_Home, SDLK_KP_7 },
    2.53 -    { XK_KP_Up, SDLK_KP_8 },
    2.54 -    { XK_KP_Prior, SDLK_KP_9 },
    2.55 -    { XK_KP_Insert, SDLK_KP_0 },
    2.56 -    { XK_KP_Decimal, SDLK_KP_PERIOD },
    2.57 -    { XK_KP_1, SDLK_KP_1 },
    2.58 -    { XK_KP_2, SDLK_KP_2 },
    2.59 -    { XK_KP_3, SDLK_KP_3 },
    2.60 -    { XK_KP_4, SDLK_KP_4 },
    2.61 -    { XK_KP_5, SDLK_KP_5 },
    2.62 -    { XK_KP_6, SDLK_KP_6 },
    2.63 -    { XK_KP_7, SDLK_KP_7 },
    2.64 -    { XK_KP_8, SDLK_KP_8 },
    2.65 -    { XK_KP_9, SDLK_KP_9 },
    2.66 -    { XK_KP_0, SDLK_KP_0 },
    2.67 -    { XK_KP_Decimal, SDLK_KP_PERIOD },
    2.68 -    { XK_Hyper_R, SDLK_APPLICATION },
    2.69 -    { XK_KP_Equal, SDLK_KP_EQUALS },
    2.70 -    { XK_F13, SDLK_F13 },
    2.71 -    { XK_F14, SDLK_F14 },
    2.72 -    { XK_F15, SDLK_F15 },
    2.73 -    { XK_F16, SDLK_F16 },
    2.74 -    { XK_F17, SDLK_F17 },
    2.75 -    { XK_F18, SDLK_F18 },
    2.76 -    { XK_F19, SDLK_F19 },
    2.77 -    { XK_F20, SDLK_F20 },
    2.78 -    { XK_F21, SDLK_F21 },
    2.79 -    { XK_F22, SDLK_F22 },
    2.80 -    { XK_F23, SDLK_F23 },
    2.81 -    { XK_F24, SDLK_F24 },
    2.82 -    { XK_Execute, SDLK_EXECUTE },
    2.83 -    { XK_Help, SDLK_HELP },
    2.84 -    { XK_Menu, SDLK_MENU },
    2.85 -    { XK_Select, SDLK_SELECT },
    2.86 -    { XK_Cancel, SDLK_STOP },
    2.87 -    { XK_Redo, SDLK_AGAIN },
    2.88 -    { XK_Undo, SDLK_UNDO },
    2.89 -    { XK_Find, SDLK_FIND },
    2.90 -    { XK_KP_Separator, SDLK_KP_COMMA },
    2.91 -    { XK_Sys_Req, SDLK_SYSREQ },
    2.92 -    { XK_Control_L, SDLK_LCTRL },
    2.93 -    { XK_Shift_L, SDLK_LSHIFT },
    2.94 -    { XK_Alt_L, SDLK_LALT },
    2.95 -    { XK_Meta_L, SDLK_LGUI },
    2.96 -    { XK_Super_L, SDLK_LGUI },
    2.97 -    { XK_Control_R, SDLK_RCTRL },
    2.98 -    { XK_Shift_R, SDLK_RSHIFT },
    2.99 -    { XK_Alt_R, SDLK_RALT },
   2.100 -    { XK_Meta_R, SDLK_RGUI },
   2.101 -    { XK_Super_R, SDLK_RGUI },
   2.102 -    { XK_Mode_switch, SDLK_MODE },
   2.103 +    SDL_Scancode scancode;
   2.104 +} KeySymToSDLScancode[] = {
   2.105 +    { XK_Return, SDL_SCANCODE_RETURN },
   2.106 +    { XK_Escape, SDL_SCANCODE_ESCAPE },
   2.107 +    { XK_BackSpace, SDL_SCANCODE_BACKSPACE },
   2.108 +    { XK_Tab, SDL_SCANCODE_TAB },
   2.109 +    { XK_Caps_Lock, SDL_SCANCODE_CAPSLOCK },
   2.110 +    { XK_F1, SDL_SCANCODE_F1 },
   2.111 +    { XK_F2, SDL_SCANCODE_F2 },
   2.112 +    { XK_F3, SDL_SCANCODE_F3 },
   2.113 +    { XK_F4, SDL_SCANCODE_F4 },
   2.114 +    { XK_F5, SDL_SCANCODE_F5 },
   2.115 +    { XK_F6, SDL_SCANCODE_F6 },
   2.116 +    { XK_F7, SDL_SCANCODE_F7 },
   2.117 +    { XK_F8, SDL_SCANCODE_F8 },
   2.118 +    { XK_F9, SDL_SCANCODE_F9 },
   2.119 +    { XK_F10, SDL_SCANCODE_F10 },
   2.120 +    { XK_F11, SDL_SCANCODE_F11 },
   2.121 +    { XK_F12, SDL_SCANCODE_F12 },
   2.122 +    { XK_Print, SDL_SCANCODE_PRINTSCREEN },
   2.123 +    { XK_Scroll_Lock, SDL_SCANCODE_SCROLLLOCK },
   2.124 +    { XK_Pause, SDL_SCANCODE_PAUSE },
   2.125 +    { XK_Insert, SDL_SCANCODE_INSERT },
   2.126 +    { XK_Home, SDL_SCANCODE_HOME },
   2.127 +    { XK_Prior, SDL_SCANCODE_PAGEUP },
   2.128 +    { XK_Delete, SDL_SCANCODE_DELETE },
   2.129 +    { XK_End, SDL_SCANCODE_END },
   2.130 +    { XK_Next, SDL_SCANCODE_PAGEDOWN },
   2.131 +    { XK_Right, SDL_SCANCODE_RIGHT },
   2.132 +    { XK_Left, SDL_SCANCODE_LEFT },
   2.133 +    { XK_Down, SDL_SCANCODE_DOWN },
   2.134 +    { XK_Up, SDL_SCANCODE_UP },
   2.135 +    { XK_Num_Lock, SDL_SCANCODE_NUMLOCKCLEAR },
   2.136 +    { XK_KP_Divide, SDL_SCANCODE_KP_DIVIDE },
   2.137 +    { XK_KP_Multiply, SDL_SCANCODE_KP_MULTIPLY },
   2.138 +    { XK_KP_Subtract, SDL_SCANCODE_KP_MINUS },
   2.139 +    { XK_KP_Add, SDL_SCANCODE_KP_PLUS },
   2.140 +    { XK_KP_Enter, SDL_SCANCODE_KP_ENTER },
   2.141 +    { XK_KP_Delete, SDL_SCANCODE_KP_PERIOD },
   2.142 +    { XK_KP_End, SDL_SCANCODE_KP_1 },
   2.143 +    { XK_KP_Down, SDL_SCANCODE_KP_2 },
   2.144 +    { XK_KP_Next, SDL_SCANCODE_KP_3 },
   2.145 +    { XK_KP_Left, SDL_SCANCODE_KP_4 },
   2.146 +    { XK_KP_Begin, SDL_SCANCODE_KP_5 },
   2.147 +    { XK_KP_Right, SDL_SCANCODE_KP_6 },
   2.148 +    { XK_KP_Home, SDL_SCANCODE_KP_7 },
   2.149 +    { XK_KP_Up, SDL_SCANCODE_KP_8 },
   2.150 +    { XK_KP_Prior, SDL_SCANCODE_KP_9 },
   2.151 +    { XK_KP_Insert, SDL_SCANCODE_KP_0 },
   2.152 +    { XK_KP_Decimal, SDL_SCANCODE_KP_PERIOD },
   2.153 +    { XK_KP_1, SDL_SCANCODE_KP_1 },
   2.154 +    { XK_KP_2, SDL_SCANCODE_KP_2 },
   2.155 +    { XK_KP_3, SDL_SCANCODE_KP_3 },
   2.156 +    { XK_KP_4, SDL_SCANCODE_KP_4 },
   2.157 +    { XK_KP_5, SDL_SCANCODE_KP_5 },
   2.158 +    { XK_KP_6, SDL_SCANCODE_KP_6 },
   2.159 +    { XK_KP_7, SDL_SCANCODE_KP_7 },
   2.160 +    { XK_KP_8, SDL_SCANCODE_KP_8 },
   2.161 +    { XK_KP_9, SDL_SCANCODE_KP_9 },
   2.162 +    { XK_KP_0, SDL_SCANCODE_KP_0 },
   2.163 +    { XK_KP_Decimal, SDL_SCANCODE_KP_PERIOD },
   2.164 +    { XK_Hyper_R, SDL_SCANCODE_APPLICATION },
   2.165 +    { XK_KP_Equal, SDL_SCANCODE_KP_EQUALS },
   2.166 +    { XK_F13, SDL_SCANCODE_F13 },
   2.167 +    { XK_F14, SDL_SCANCODE_F14 },
   2.168 +    { XK_F15, SDL_SCANCODE_F15 },
   2.169 +    { XK_F16, SDL_SCANCODE_F16 },
   2.170 +    { XK_F17, SDL_SCANCODE_F17 },
   2.171 +    { XK_F18, SDL_SCANCODE_F18 },
   2.172 +    { XK_F19, SDL_SCANCODE_F19 },
   2.173 +    { XK_F20, SDL_SCANCODE_F20 },
   2.174 +    { XK_F21, SDL_SCANCODE_F21 },
   2.175 +    { XK_F22, SDL_SCANCODE_F22 },
   2.176 +    { XK_F23, SDL_SCANCODE_F23 },
   2.177 +    { XK_F24, SDL_SCANCODE_F24 },
   2.178 +    { XK_Execute, SDL_SCANCODE_EXECUTE },
   2.179 +    { XK_Help, SDL_SCANCODE_HELP },
   2.180 +    { XK_Menu, SDL_SCANCODE_MENU },
   2.181 +    { XK_Select, SDL_SCANCODE_SELECT },
   2.182 +    { XK_Cancel, SDL_SCANCODE_STOP },
   2.183 +    { XK_Redo, SDL_SCANCODE_AGAIN },
   2.184 +    { XK_Undo, SDL_SCANCODE_UNDO },
   2.185 +    { XK_Find, SDL_SCANCODE_FIND },
   2.186 +    { XK_KP_Separator, SDL_SCANCODE_KP_COMMA },
   2.187 +    { XK_Sys_Req, SDL_SCANCODE_SYSREQ },
   2.188 +    { XK_Control_L, SDL_SCANCODE_LCTRL },
   2.189 +    { XK_Shift_L, SDL_SCANCODE_LSHIFT },
   2.190 +    { XK_Alt_L, SDL_SCANCODE_LALT },
   2.191 +    { XK_Meta_L, SDL_SCANCODE_LGUI },
   2.192 +    { XK_Super_L, SDL_SCANCODE_LGUI },
   2.193 +    { XK_Control_R, SDL_SCANCODE_RCTRL },
   2.194 +    { XK_Shift_R, SDL_SCANCODE_RSHIFT },
   2.195 +    { XK_Alt_R, SDL_SCANCODE_RALT },
   2.196 +    { XK_Meta_R, SDL_SCANCODE_RGUI },
   2.197 +    { XK_Super_R, SDL_SCANCODE_RGUI },
   2.198 +    { XK_Mode_switch, SDL_SCANCODE_MODE },
   2.199  };
   2.200  
   2.201  static const struct
   2.202 @@ -144,11 +144,11 @@
   2.203  };
   2.204  /* *INDENT-OFF* */
   2.205  
   2.206 -static SDL_Keycode
   2.207 -X11_KeyCodeToSDLKey(Display *display, KeyCode keycode)
   2.208 +/* This function only works for keyboards in US QWERTY layout */
   2.209 +static SDL_Scancode
   2.210 +X11_KeyCodeToSDLScancode(Display *display, KeyCode keycode)
   2.211  {
   2.212      KeySym keysym;
   2.213 -    unsigned int ucs4;
   2.214      int i;
   2.215  
   2.216  #if SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM
   2.217 @@ -157,20 +157,40 @@
   2.218      keysym = XKeycodeToKeysym(display, keycode, 0);
   2.219  #endif
   2.220      if (keysym == NoSymbol) {
   2.221 -        return SDLK_UNKNOWN;
   2.222 +        return SDL_SCANCODE_UNKNOWN;
   2.223      }
   2.224  
   2.225 -    ucs4 = X11_KeySymToUcs4(keysym);
   2.226 -    if (ucs4) {
   2.227 -        return (SDL_Keycode) ucs4;
   2.228 +    if (keysym >= XK_A && keysym <= XK_Z) {
   2.229 +        return SDL_SCANCODE_A + (keysym - XK_A);
   2.230      }
   2.231  
   2.232 -    for (i = 0; i < SDL_arraysize(KeySymToSDLKey); ++i) {
   2.233 -        if (keysym == KeySymToSDLKey[i].keysym) {
   2.234 -            return KeySymToSDLKey[i].sdlkey;
   2.235 +    if (keysym >= XK_0 && keysym <= XK_9) {
   2.236 +        return SDL_SCANCODE_0 + (keysym - XK_0);
   2.237 +    }
   2.238 +
   2.239 +    for (i = 0; i < SDL_arraysize(KeySymToSDLScancode); ++i) {
   2.240 +        if (keysym == KeySymToSDLScancode[i].keysym) {
   2.241 +            return KeySymToSDLScancode[i].scancode;
   2.242          }
   2.243      }
   2.244 -    return SDLK_UNKNOWN;
   2.245 +    return SDL_SCANCODE_UNKNOWN;
   2.246 +}
   2.247 +
   2.248 +static Uint32
   2.249 +X11_KeyCodeToUcs4(Display *display, KeyCode keycode)
   2.250 +{
   2.251 +    KeySym keysym;
   2.252 +
   2.253 +#if SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM
   2.254 +    keysym = XkbKeycodeToKeysym(display, keycode, 0, 0);
   2.255 +#else
   2.256 +    keysym = XKeycodeToKeysym(display, keycode, 0);
   2.257 +#endif
   2.258 +    if (keysym == NoSymbol) {
   2.259 +        return 0;
   2.260 +    }
   2.261 +
   2.262 +    return X11_KeySymToUcs4(keysym);
   2.263  }
   2.264  
   2.265  int
   2.266 @@ -242,17 +262,12 @@
   2.267              sym = XKeycodeToKeysym(data->display, i, 0);
   2.268  #endif
   2.269              if (sym != NoSymbol) {
   2.270 -                SDL_Keycode key;
   2.271 +                SDL_Scancode scancode;
   2.272                  printf("code = %d, sym = 0x%X (%s) ", i - min_keycode,
   2.273                         (unsigned int) sym, XKeysymToString(sym));
   2.274 -                key = X11_KeyCodeToSDLKey(data->display, i);
   2.275 -                for (j = 0; j < SDL_arraysize(keymap); ++j) {
   2.276 -                    if (keymap[j] == key) {
   2.277 -                        data->key_layout[i] = (SDL_Scancode) j;
   2.278 -                        break;
   2.279 -                    }
   2.280 -                }
   2.281 -                if (j == SDL_arraysize(keymap)) {
   2.282 +                scancode = X11_KeyCodeToSDLScancode(data->display, i);
   2.283 +                data->key_layout[i] = scancode;
   2.284 +                if (scancode == SDL_SCANCODE_UNKNOWN) {
   2.285                      printf("scancode not found\n");
   2.286                  } else {
   2.287                      printf("scancode = %d (%s)\n", j, SDL_GetScancodeName(j));
   2.288 @@ -276,9 +291,9 @@
   2.289      SDL_Scancode scancode;
   2.290      SDL_Keycode keymap[SDL_NUM_SCANCODES];
   2.291  
   2.292 -    SDL_zero(keymap);
   2.293 -
   2.294 +    SDL_GetDefaultKeymap(keymap);
   2.295      for (i = 0; i < SDL_arraysize(data->key_layout); i++) {
   2.296 +        Uint32 key;
   2.297  
   2.298          /* Make sure this is a valid scancode */
   2.299          scancode = data->key_layout[i];
   2.300 @@ -286,7 +301,11 @@
   2.301              continue;
   2.302          }
   2.303  
   2.304 -        keymap[scancode] = X11_KeyCodeToSDLKey(data->display, (KeyCode)i);
   2.305 +        /* See if there is a UCS keycode for this scancode */
   2.306 +        key = X11_KeyCodeToUcs4(data->display, (KeyCode)i);
   2.307 +        if (key) {
   2.308 +            keymap[scancode] = key;
   2.309 +        }
   2.310      }
   2.311      SDL_SetKeymap(0, keymap, SDL_NUM_SCANCODES);
   2.312  }