src/events/SDL_keyboard.c
changeset 2303 d87417504c75
parent 2300 c97ad1abe05b
child 2305 fbe8ff44c519
     1.1 --- a/src/events/SDL_keyboard.c	Mon Feb 04 17:25:33 2008 +0000
     1.2 +++ b/src/events/SDL_keyboard.c	Tue Feb 05 07:19:23 2008 +0000
     1.3 @@ -27,18 +27,475 @@
     1.4  #include "SDL_events.h"
     1.5  #include "SDL_events_c.h"
     1.6  #include "SDL_sysevents.h"
     1.7 -#include "SDL_keynames.h"
     1.8  
     1.9  
    1.10  /* Global keyboard information */
    1.11 -int SDL_TranslateUNICODE = 0;
    1.12  static int SDL_num_keyboards;
    1.13  static int SDL_current_keyboard;
    1.14  static SDL_Keyboard **SDL_keyboards;
    1.15  
    1.16 +static SDLKey SDL_default_keymap[SDL_NUM_SCANCODES] = {
    1.17 +    0, 0, 0, 0,
    1.18 +    'a',
    1.19 +    'b',
    1.20 +    'c',
    1.21 +    'd',
    1.22 +    'e',
    1.23 +    'f',
    1.24 +    'g',
    1.25 +    'h',
    1.26 +    'i',
    1.27 +    'j',
    1.28 +    'k',
    1.29 +    'l',
    1.30 +    'm',
    1.31 +    'n',
    1.32 +    'o',
    1.33 +    'p',
    1.34 +    'q',
    1.35 +    'r',
    1.36 +    's',
    1.37 +    't',
    1.38 +    'u',
    1.39 +    'v',
    1.40 +    'w',
    1.41 +    'x',
    1.42 +    'y',
    1.43 +    'z',
    1.44 +    '1',
    1.45 +    '2',
    1.46 +    '3',
    1.47 +    '4',
    1.48 +    '5',
    1.49 +    '6',
    1.50 +    '7',
    1.51 +    '8',
    1.52 +    '9',
    1.53 +    '0',
    1.54 +    SDLK_RETURN,
    1.55 +    SDLK_ESCAPE,
    1.56 +    SDLK_BACKSPACE,
    1.57 +    SDLK_TAB,
    1.58 +    SDLK_SPACE,
    1.59 +    '-',
    1.60 +    '=',
    1.61 +    '[',
    1.62 +    ']',
    1.63 +    '\\',
    1.64 +    '#',
    1.65 +    ';',
    1.66 +    '\'',
    1.67 +    '`',
    1.68 +    ',',
    1.69 +    '.',
    1.70 +    '/',
    1.71 +    SDLK_CAPSLOCK,
    1.72 +    SDLK_F1,
    1.73 +    SDLK_F2,
    1.74 +    SDLK_F3,
    1.75 +    SDLK_F4,
    1.76 +    SDLK_F5,
    1.77 +    SDLK_F6,
    1.78 +    SDLK_F7,
    1.79 +    SDLK_F8,
    1.80 +    SDLK_F9,
    1.81 +    SDLK_F10,
    1.82 +    SDLK_F11,
    1.83 +    SDLK_F12,
    1.84 +    SDLK_PRINTSCREEN,
    1.85 +    SDLK_SCROLLLOCK,
    1.86 +    SDLK_PAUSE,
    1.87 +    SDLK_INSERT,
    1.88 +    SDLK_HOME,
    1.89 +    SDLK_PAGEUP,
    1.90 +    SDLK_DELETE,
    1.91 +    SDLK_END,
    1.92 +    SDLK_PAGEDOWN,
    1.93 +    SDLK_RIGHT,
    1.94 +    SDLK_LEFT,
    1.95 +    SDLK_DOWN,
    1.96 +    SDLK_UP,
    1.97 +    SDLK_NUMLOCKCLEAR,
    1.98 +    SDLK_KP_DIVIDE,
    1.99 +    SDLK_KP_MULTIPLY,
   1.100 +    SDLK_KP_MINUS,
   1.101 +    SDLK_KP_PLUS,
   1.102 +    SDLK_KP_ENTER,
   1.103 +    SDLK_KP_1,
   1.104 +    SDLK_KP_2,
   1.105 +    SDLK_KP_3,
   1.106 +    SDLK_KP_4,
   1.107 +    SDLK_KP_5,
   1.108 +    SDLK_KP_6,
   1.109 +    SDLK_KP_7,
   1.110 +    SDLK_KP_8,
   1.111 +    SDLK_KP_9,
   1.112 +    SDLK_KP_0,
   1.113 +    SDLK_KP_PERIOD,
   1.114 +    0,
   1.115 +    SDLK_APPLICATION,
   1.116 +    SDLK_POWER,
   1.117 +    SDLK_KP_EQUALS,
   1.118 +    SDLK_F13,
   1.119 +    SDLK_F14,
   1.120 +    SDLK_F15,
   1.121 +    SDLK_F16,
   1.122 +    SDLK_F17,
   1.123 +    SDLK_F18,
   1.124 +    SDLK_F19,
   1.125 +    SDLK_F20,
   1.126 +    SDLK_F21,
   1.127 +    SDLK_F22,
   1.128 +    SDLK_F23,
   1.129 +    SDLK_F24,
   1.130 +    SDLK_EXECUTE,
   1.131 +    SDLK_HELP,
   1.132 +    SDLK_MENU,
   1.133 +    SDLK_SELECT,
   1.134 +    SDLK_STOP,
   1.135 +    SDLK_AGAIN,
   1.136 +    SDLK_UNDO,
   1.137 +    SDLK_CUT,
   1.138 +    SDLK_COPY,
   1.139 +    SDLK_PASTE,
   1.140 +    SDLK_FIND,
   1.141 +    SDLK_MUTE,
   1.142 +    SDLK_VOLUMEUP,
   1.143 +    SDLK_VOLUMEDOWN,
   1.144 +    0, 0, 0,
   1.145 +    SDLK_KP_COMMA,
   1.146 +    SDLK_KP_EQUALSAS400,
   1.147 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   1.148 +    SDLK_ALTERASE,
   1.149 +    SDLK_SYSREQ,
   1.150 +    SDLK_CANCEL,
   1.151 +    SDLK_CLEAR,
   1.152 +    SDLK_PRIOR,
   1.153 +    SDLK_RETURN2,
   1.154 +    SDLK_SEPARATOR,
   1.155 +    SDLK_OUT,
   1.156 +    SDLK_OPER,
   1.157 +    SDLK_CLEARAGAIN,
   1.158 +    SDLK_CRSEL,
   1.159 +    SDLK_EXSEL,
   1.160 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   1.161 +    SDLK_KP_00,
   1.162 +    SDLK_KP_000,
   1.163 +    SDLK_THOUSANDSSEPARATOR,
   1.164 +    SDLK_DECIMALSEPARATOR,
   1.165 +    SDLK_CURRENCYUNIT,
   1.166 +    SDLK_CURRENCYSUBUNIT,
   1.167 +    SDLK_KP_LEFTPAREN,
   1.168 +    SDLK_KP_RIGHTPAREN,
   1.169 +    SDLK_KP_LEFTBRACE,
   1.170 +    SDLK_KP_RIGHTBRACE,
   1.171 +    SDLK_KP_TAB,
   1.172 +    SDLK_KP_BACKSPACE,
   1.173 +    SDLK_KP_A,
   1.174 +    SDLK_KP_B,
   1.175 +    SDLK_KP_C,
   1.176 +    SDLK_KP_D,
   1.177 +    SDLK_KP_E,
   1.178 +    SDLK_KP_F,
   1.179 +    SDLK_KP_XOR,
   1.180 +    SDLK_KP_POWER,
   1.181 +    SDLK_KP_PERCENT,
   1.182 +    SDLK_KP_LESS,
   1.183 +    SDLK_KP_GREATER,
   1.184 +    SDLK_KP_AMPERSAND,
   1.185 +    SDLK_KP_DBLAMPERSAND,
   1.186 +    SDLK_KP_VERTICALBAR,
   1.187 +    SDLK_KP_DBLVERTICALBAR,
   1.188 +    SDLK_KP_COLON,
   1.189 +    SDLK_KP_HASH,
   1.190 +    SDLK_KP_SPACE,
   1.191 +    SDLK_KP_AT,
   1.192 +    SDLK_KP_EXCLAM,
   1.193 +    SDLK_KP_MEMSTORE,
   1.194 +    SDLK_KP_MEMRECALL,
   1.195 +    SDLK_KP_MEMCLEAR,
   1.196 +    SDLK_KP_MEMADD,
   1.197 +    SDLK_KP_MEMSUBTRACT,
   1.198 +    SDLK_KP_MEMMULTIPLY,
   1.199 +    SDLK_KP_MEMDIVIDE,
   1.200 +    SDLK_KP_PLUSMINUS,
   1.201 +    SDLK_KP_CLEAR,
   1.202 +    SDLK_KP_CLEARENTRY,
   1.203 +    SDLK_KP_BINARY,
   1.204 +    SDLK_KP_OCTAL,
   1.205 +    SDLK_KP_DECIMAL,
   1.206 +    SDLK_KP_HEXADECIMAL,
   1.207 +    0, 0,
   1.208 +    SDLK_LCTRL,
   1.209 +    SDLK_LSHIFT,
   1.210 +    SDLK_LALT,
   1.211 +    SDLK_LGUI,
   1.212 +    SDLK_RCTRL,
   1.213 +    SDLK_RSHIFT,
   1.214 +    SDLK_RALT,
   1.215 +    SDLK_RGUI,
   1.216 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   1.217 +    SDLK_MODE,
   1.218 +    SDLK_AUDIONEXT,
   1.219 +    SDLK_AUDIOPREV,
   1.220 +    SDLK_AUDIOSTOP,
   1.221 +    SDLK_AUDIOPLAY,
   1.222 +    SDLK_AUDIOMUTE,
   1.223 +    SDLK_MEDIASELECT,
   1.224 +    SDLK_MAIL,
   1.225 +    SDLK_CALCULATOR,
   1.226 +    SDLK_COMPUTER,
   1.227 +    SDLK_AC_SEARCH,
   1.228 +    SDLK_AC_HOME,
   1.229 +    SDLK_AC_BACK,
   1.230 +    SDLK_AC_FORWARD,
   1.231 +    SDLK_AC_STOP,
   1.232 +    SDLK_AC_REFRESH,
   1.233 +    SDLK_AC_BOOKMARKS,
   1.234 +    SDLK_BRIGHTNESSDOWN,
   1.235 +    SDLK_BRIGHTNESSUP,
   1.236 +    SDLK_DISPLAYSWITCH,
   1.237 +    SDLK_KBDILLUMTOGGLE,
   1.238 +    SDLK_KBDILLUMDOWN,
   1.239 +    SDLK_KBDILLUMUP,
   1.240 +    SDLK_EJECT,
   1.241 +    SDLK_SLEEP,
   1.242 +};
   1.243 +
   1.244 +static const char *SDL_scancode_names[SDL_NUM_SCANCODES] = {
   1.245 +    NULL, NULL, NULL, NULL,
   1.246 +    "A",
   1.247 +    "B",
   1.248 +    "C",
   1.249 +    "D",
   1.250 +    "E",
   1.251 +    "F",
   1.252 +    "G",
   1.253 +    "H",
   1.254 +    "I",
   1.255 +    "J",
   1.256 +    "K",
   1.257 +    "L",
   1.258 +    "M",
   1.259 +    "N",
   1.260 +    "O",
   1.261 +    "P",
   1.262 +    "Q",
   1.263 +    "R",
   1.264 +    "S",
   1.265 +    "T",
   1.266 +    "U",
   1.267 +    "V",
   1.268 +    "W",
   1.269 +    "X",
   1.270 +    "Y",
   1.271 +    "Z",
   1.272 +    "1",
   1.273 +    "2",
   1.274 +    "3",
   1.275 +    "4",
   1.276 +    "5",
   1.277 +    "6",
   1.278 +    "7",
   1.279 +    "8",
   1.280 +    "9",
   1.281 +    "0",
   1.282 +    "Return",
   1.283 +    "Escape",
   1.284 +    "Backspace",
   1.285 +    "Tab",
   1.286 +    "Space",
   1.287 +    "-",
   1.288 +    "=",
   1.289 +    "[",
   1.290 +    "]",
   1.291 +    "\\",
   1.292 +    "#",
   1.293 +    ";",
   1.294 +    "'",
   1.295 +    "`",
   1.296 +    ",",
   1.297 +    ".",
   1.298 +    "/",
   1.299 +    "CapsLock",
   1.300 +    "F1",
   1.301 +    "F2",
   1.302 +    "F3",
   1.303 +    "F4",
   1.304 +    "F5",
   1.305 +    "F6",
   1.306 +    "F7",
   1.307 +    "F8",
   1.308 +    "F9",
   1.309 +    "F10",
   1.310 +    "F11",
   1.311 +    "F12",
   1.312 +    "PrintScreen",
   1.313 +    "ScrollLock",
   1.314 +    "Pause",
   1.315 +    "Insert",
   1.316 +    "Home",
   1.317 +    "PageUp",
   1.318 +    "Delete",
   1.319 +    "End",
   1.320 +    "PageDown",
   1.321 +    "Right",
   1.322 +    "Left",
   1.323 +    "Down",
   1.324 +    "Up",
   1.325 +    "Numlock",
   1.326 +    "Keypad /",
   1.327 +    "Keypad *",
   1.328 +    "Keypad -",
   1.329 +    "Keypad +",
   1.330 +    "Keypad Enter",
   1.331 +    "Keypad 1",
   1.332 +    "Keypad 2",
   1.333 +    "Keypad 3",
   1.334 +    "Keypad 4",
   1.335 +    "Keypad 5",
   1.336 +    "Keypad 6",
   1.337 +    "Keypad 7",
   1.338 +    "Keypad 8",
   1.339 +    "Keypad 9",
   1.340 +    "Keypad 0",
   1.341 +    "Keypad .",
   1.342 +    NULL,
   1.343 +    "Application",
   1.344 +    "Power",
   1.345 +    "Keypad =",
   1.346 +    "F13",
   1.347 +    "F14",
   1.348 +    "F15",
   1.349 +    "F16",
   1.350 +    "F17",
   1.351 +    "F18",
   1.352 +    "F19",
   1.353 +    "F20",
   1.354 +    "F21",
   1.355 +    "F22",
   1.356 +    "F23",
   1.357 +    "F24",
   1.358 +    "Execute",
   1.359 +    "Help",
   1.360 +    "Menu",
   1.361 +    "Select",
   1.362 +    "Stop",
   1.363 +    "Again",
   1.364 +    "Undo",
   1.365 +    "Cut",
   1.366 +    "Copy",
   1.367 +    "Paste",
   1.368 +    "Find",
   1.369 +    "Mute",
   1.370 +    "VolumeUp",
   1.371 +    "VolumeDown",
   1.372 +    NULL, NULL, NULL,
   1.373 +    "Keypad ,",
   1.374 +    "Keypad = (AS400)",
   1.375 +    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
   1.376 +    NULL, NULL, NULL, NULL, NULL, NULL,
   1.377 +    "AltErase",
   1.378 +    "SysReq",
   1.379 +    "Cancel",
   1.380 +    "Clear",
   1.381 +    "Prior",
   1.382 +    "Return",
   1.383 +    "Separator",
   1.384 +    "Out",
   1.385 +    "Oper",
   1.386 +    "Clear / Again",
   1.387 +    "CrSel",
   1.388 +    "ExSel",
   1.389 +    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
   1.390 +    "Keypad 00",
   1.391 +    "Keypad 000",
   1.392 +    "ThousandsSeparator",
   1.393 +    "DecimalSeparator",
   1.394 +    "CurrencyUnit",
   1.395 +    "CurrencySubUnit",
   1.396 +    "Keypad (",
   1.397 +    "Keypad )",
   1.398 +    "Keypad {",
   1.399 +    "Keypad }",
   1.400 +    "Keypad Tab",
   1.401 +    "Keypad Backspace",
   1.402 +    "Keypad A",
   1.403 +    "Keypad B",
   1.404 +    "Keypad C",
   1.405 +    "Keypad D",
   1.406 +    "Keypad E",
   1.407 +    "Keypad F",
   1.408 +    "Keypad XOR",
   1.409 +    "Keypad ^",
   1.410 +    "Keypad %",
   1.411 +    "Keypad <",
   1.412 +    "Keypad >",
   1.413 +    "Keypad &",
   1.414 +    "Keypad &&",
   1.415 +    "Keypad |",
   1.416 +    "Keypad ||",
   1.417 +    "Keypad :",
   1.418 +    "Keypad #",
   1.419 +    "Keypad Space",
   1.420 +    "Keypad @",
   1.421 +    "Keypad !",
   1.422 +    "Keypad MemStore",
   1.423 +    "Keypad MemRecall",
   1.424 +    "Keypad MemClear",
   1.425 +    "Keypad MemAdd",
   1.426 +    "Keypad MemSubtract",
   1.427 +    "Keypad MemMultiply",
   1.428 +    "Keypad MemDivide",
   1.429 +    "Keypad +/-",
   1.430 +    "Keypad Clear",
   1.431 +    "Keypad ClearEntry",
   1.432 +    "Keypad Binary",
   1.433 +    "Keypad Octal",
   1.434 +    "Keypad Decimal",
   1.435 +    "Keypad Hexadecimal",
   1.436 +    NULL, NULL,
   1.437 +    "Left Ctrl",
   1.438 +    "Left Shift",
   1.439 +    "Left Alt",
   1.440 +    "Left GUI",
   1.441 +    "Right Ctrl",
   1.442 +    "Right Shift",
   1.443 +    "Right Alt",
   1.444 +    "Right GUI",
   1.445 +    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
   1.446 +    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
   1.447 +    NULL,
   1.448 +    "ModeSwitch",
   1.449 +    "AudioNext",
   1.450 +    "AudioPrev",
   1.451 +    "AudioStop",
   1.452 +    "AudioPlay",
   1.453 +    "AudioMute",
   1.454 +    "MediaSelect",
   1.455 +    "Mail",
   1.456 +    "Calculator",
   1.457 +    "Computer",
   1.458 +    "AC Search",
   1.459 +    "AC Home",
   1.460 +    "AC Back",
   1.461 +    "AC Forward",
   1.462 +    "AC Stop",
   1.463 +    "AC Refresh",
   1.464 +    "AC Bookmarks",
   1.465 +    "BrightnessDown",
   1.466 +    "BrightnessUp",
   1.467 +    "DisplaySwitch",
   1.468 +    "KBDIllumToggle",
   1.469 +    "KBDIllumDown",
   1.470 +    "KBDIllumUp",
   1.471 +    "Eject",
   1.472 +    "Sleep",
   1.473 +};
   1.474 +
   1.475  /* Taken from SDL_iconv() */
   1.476 -char *
   1.477 -SDL_Ucs4ToUtf8(Uint32 ch, char *dst)
   1.478 +static char *
   1.479 +SDL_UCS4ToUTF8(Uint32 ch, char *dst)
   1.480  {
   1.481      Uint8 *p = (Uint8 *) dst;
   1.482      if (ch <= 0x7F) {
   1.483 @@ -82,9 +539,6 @@
   1.484  int
   1.485  SDL_KeyboardInit(void)
   1.486  {
   1.487 -    /* Set default mode of UNICODE translation */
   1.488 -    SDL_EnableUNICODE(DEFAULT_UNICODE_TRANSLATION);
   1.489 -
   1.490      return (0);
   1.491  }
   1.492  
   1.493 @@ -148,170 +602,45 @@
   1.494  SDL_ResetKeyboard(int index)
   1.495  {
   1.496      SDL_Keyboard *keyboard = SDL_GetKeyboard(index);
   1.497 -    int key;
   1.498 +    SDL_scancode scancode;
   1.499  
   1.500      if (!keyboard) {
   1.501          return;
   1.502      }
   1.503  
   1.504 -    for (key = SDLK_FIRST; key < SDLK_LAST; ++key) {
   1.505 -        if (keyboard->keystate[key] == SDL_PRESSED) {
   1.506 -            SDL_SendKeyboardKey(index, SDL_RELEASED, 0,
   1.507 -                                key | SDL_KEY_CAN_BE_PHYSICAL_BIT);
   1.508 +    for (scancode = 0; scancode < SDL_NUM_SCANCODES; ++scancode) {
   1.509 +        if (keyboard->keystate[scancode] == SDL_PRESSED) {
   1.510 +            SDL_SendKeyboardKey(index, SDL_RELEASED, scancode);
   1.511          }
   1.512      }
   1.513  }
   1.514  
   1.515  void
   1.516 -SDL_KeyboardQuit(void)
   1.517 +SDL_GetDefaultKeymap(SDLKey * keymap)
   1.518  {
   1.519 -    int i;
   1.520 -
   1.521 -    for (i = 0; i < SDL_num_keyboards; ++i) {
   1.522 -        SDL_DelKeyboard(i);
   1.523 -    }
   1.524 -    SDL_num_keyboards = 0;
   1.525 -    SDL_current_keyboard = 0;
   1.526 -
   1.527 -    if (SDL_keyboards) {
   1.528 -        SDL_free(SDL_keyboards);
   1.529 -        SDL_keyboards = NULL;
   1.530 -    }
   1.531 -}
   1.532 -
   1.533 -int
   1.534 -SDL_GetNumKeyboards(void)
   1.535 -{
   1.536 -    return SDL_num_keyboards;
   1.537 -}
   1.538 -
   1.539 -int
   1.540 -SDL_SelectKeyboard(int index)
   1.541 -{
   1.542 -    if (index >= 0 && index < SDL_num_keyboards) {
   1.543 -        SDL_current_keyboard = index;
   1.544 -    }
   1.545 -    return SDL_current_keyboard;
   1.546 -}
   1.547 -
   1.548 -int
   1.549 -SDL_EnableUNICODE(int enable)
   1.550 -{
   1.551 -    int old_mode;
   1.552 -
   1.553 -    old_mode = SDL_TranslateUNICODE;
   1.554 -    if (enable >= 0) {
   1.555 -        SDL_TranslateUNICODE = enable;
   1.556 -    }
   1.557 -    return (old_mode);
   1.558 -}
   1.559 -
   1.560 -Uint8 *
   1.561 -SDL_GetKeyState(int *numkeys)
   1.562 -{
   1.563 -    SDL_Keyboard *keyboard = SDL_GetKeyboard(SDL_current_keyboard);
   1.564 -
   1.565 -    if (numkeys != (int *) 0) {
   1.566 -        *numkeys = SDLK_LAST;
   1.567 -    }
   1.568 -
   1.569 -    if (!keyboard) {
   1.570 -        return NULL;
   1.571 -    }
   1.572 -    return keyboard->keystate;
   1.573 -}
   1.574 -
   1.575 -SDLMod
   1.576 -SDL_GetModState(void)
   1.577 -{
   1.578 -    SDL_Keyboard *keyboard = SDL_GetKeyboard(SDL_current_keyboard);
   1.579 -
   1.580 -    if (!keyboard) {
   1.581 -        return KMOD_NONE;
   1.582 -    }
   1.583 -    return keyboard->modstate;
   1.584 +    SDL_memcpy(keymap, SDL_default_keymap, sizeof(SDL_default_keymap));
   1.585  }
   1.586  
   1.587  void
   1.588 -SDL_SetModState(SDLMod modstate)
   1.589 +SDL_SetKeymap(int index, int start, SDLKey * keys, int length)
   1.590  {
   1.591 -    SDL_Keyboard *keyboard = SDL_GetKeyboard(SDL_current_keyboard);
   1.592 +    SDL_Keyboard *keyboard = SDL_GetKeyboard(index);
   1.593  
   1.594      if (!keyboard) {
   1.595          return;
   1.596      }
   1.597 -    keyboard->modstate = modstate;
   1.598 -}
   1.599  
   1.600 -SDLKey
   1.601 -SDL_GetLayoutKey(SDLKey physicalKey)
   1.602 -{
   1.603 -    SDL_VideoDevice *_this = SDL_GetVideoDevice();
   1.604 -    if (_this && _this->GetLayoutKey) {
   1.605 -        return _this->GetLayoutKey(_this, physicalKey)
   1.606 -            | (physicalKey & SDL_KEY_KEYPAD_BIT);
   1.607 -    } else {
   1.608 -        return physicalKey;
   1.609 -    }
   1.610 -}
   1.611 -
   1.612 -const char *
   1.613 -SDL_GetKeyName(SDLKey layoutKey)
   1.614 -{
   1.615 -    const char *keyname = NULL;
   1.616 -
   1.617 -    if ((layoutKey & SDL_KEY_LAYOUT_SPECIAL_BIT) != 0) {
   1.618 -        SDL_VideoDevice *_this = SDL_GetVideoDevice();
   1.619 -        if (_this && _this->GetSpecialKeyName) {
   1.620 -            keyname = _this->GetSpecialKeyName(_this, layoutKey);
   1.621 -        }
   1.622 -    } else if ((layoutKey & SDL_KEY_CAN_BE_PHYSICAL_BIT) == 0) {
   1.623 -        /* SDLK_INDEX(layoutKey) is the unicode code point of the
   1.624 -           character generated by the key */
   1.625 -        static char buffer[9];  /* 6 (maximal UTF-8 char length) + 2 ([] for keypad) + 1 (null teminator) */
   1.626 -        char *bufferPtr = &buffer[1];
   1.627 -        Uint32 codepoint = SDLK_INDEX(layoutKey);
   1.628 -
   1.629 -        /* Unaccented letter keys on latin keyboards are normally
   1.630 -           labeled in upper case (and probably on others like Greek or
   1.631 -           Cyrillic too, so if you happen to know for sure, please
   1.632 -           adapt this). */
   1.633 -        if (codepoint >= 'a' && codepoint <= 'z') {
   1.634 -            codepoint -= 32;
   1.635 -        }
   1.636 -
   1.637 -        bufferPtr = SDL_Ucs4ToUtf8(codepoint, bufferPtr);
   1.638 -        *bufferPtr = '\0';
   1.639 -
   1.640 -        if ((layoutKey & SDL_KEY_KEYPAD_BIT) != 0) {
   1.641 -            buffer[0] = '[';
   1.642 -            *bufferPtr++ = ']';
   1.643 -            *bufferPtr = '\0';
   1.644 -            keyname = buffer;
   1.645 -        } else {
   1.646 -            keyname = &buffer[1];
   1.647 -        }
   1.648 -    } else {
   1.649 -        /* SDLK_INDEX(layoutKey) is a physical key number */
   1.650 -        if (SDLK_INDEX(layoutKey) < SDL_arraysize(SDL_keynames)) {
   1.651 -            keyname = SDL_keynames[SDLK_INDEX(layoutKey)];
   1.652 -        }
   1.653 +    if (start < 0 || start + length > SDL_NUM_SCANCODES) {
   1.654 +        return;
   1.655      }
   1.656  
   1.657 -    if (keyname == NULL) {
   1.658 -        keyname = SDL_keynames[SDLK_INDEX(SDLK_UNKNOWN)];
   1.659 -    }
   1.660 -
   1.661 -    return keyname;
   1.662 +    SDL_memcpy(&keyboard->keymap[start], keys, sizeof(*keys) * length);
   1.663  }
   1.664  
   1.665  void
   1.666 -SDL_SetKeyName(SDLKey physicalKey, const char *name)
   1.667 +SDL_SetScancodeName(SDL_scancode scancode, const char *name)
   1.668  {
   1.669 -    physicalKey = SDLK_INDEX(physicalKey);
   1.670 -    if (physicalKey < SDL_arraysize(SDL_keynames)) {
   1.671 -        SDL_keynames[physicalKey] = name;
   1.672 -    }
   1.673 +    SDL_scancode_names[scancode] = name;
   1.674  }
   1.675  
   1.676  void
   1.677 @@ -366,94 +695,89 @@
   1.678  }
   1.679  
   1.680  int
   1.681 -SDL_SendKeyboardKey(int index, Uint8 state, Uint8 scancode,
   1.682 -                    SDLKey physicalKey)
   1.683 +SDL_SendKeyboardKey(int index, Uint8 state, SDL_scancode scancode)
   1.684  {
   1.685      SDL_Keyboard *keyboard = SDL_GetKeyboard(index);
   1.686      int posted;
   1.687      Uint16 modstate;
   1.688      Uint8 type;
   1.689  
   1.690 -    if (!keyboard || physicalKey == SDLK_NONE) {
   1.691 +    if (!keyboard || !scancode) {
   1.692          return 0;
   1.693      }
   1.694  #if 0
   1.695 -    printf("The '%s' key has been %s\n", SDL_GetKeyName(physicalKey),
   1.696 +    printf("The '%s' key has been %s\n", SDL_GetScancodeName(scancode),
   1.697             state == SDL_PRESSED ? "pressed" : "released");
   1.698  #endif
   1.699      if (state == SDL_PRESSED) {
   1.700          modstate = keyboard->modstate;
   1.701 -        switch (physicalKey) {
   1.702 -        case SDLK_UNKNOWN:
   1.703 -            break;
   1.704 -        case SDLK_KP_NUMLOCKCLEAR:
   1.705 +        switch (scancode) {
   1.706 +        case SDL_SCANCODE_NUMLOCKCLEAR:
   1.707              keyboard->modstate ^= KMOD_NUM;
   1.708              break;
   1.709 -        case SDLK_CAPSLOCK:
   1.710 +        case SDL_SCANCODE_CAPSLOCK:
   1.711              keyboard->modstate ^= KMOD_CAPS;
   1.712              break;
   1.713 -        case SDLK_LCTRL:
   1.714 +        case SDL_SCANCODE_LCTRL:
   1.715              keyboard->modstate |= KMOD_LCTRL;
   1.716              break;
   1.717 -        case SDLK_RCTRL:
   1.718 +        case SDL_SCANCODE_RCTRL:
   1.719              keyboard->modstate |= KMOD_RCTRL;
   1.720              break;
   1.721 -        case SDLK_LSHIFT:
   1.722 +        case SDL_SCANCODE_LSHIFT:
   1.723              keyboard->modstate |= KMOD_LSHIFT;
   1.724              break;
   1.725 -        case SDLK_RSHIFT:
   1.726 +        case SDL_SCANCODE_RSHIFT:
   1.727              keyboard->modstate |= KMOD_RSHIFT;
   1.728              break;
   1.729 -        case SDLK_LALT:
   1.730 +        case SDL_SCANCODE_LALT:
   1.731              keyboard->modstate |= KMOD_LALT;
   1.732              break;
   1.733 -        case SDLK_RALT:
   1.734 +        case SDL_SCANCODE_RALT:
   1.735              keyboard->modstate |= KMOD_RALT;
   1.736              break;
   1.737 -        case SDLK_LMETA:
   1.738 -            keyboard->modstate |= KMOD_LMETA;
   1.739 +        case SDL_SCANCODE_LGUI:
   1.740 +            keyboard->modstate |= KMOD_LGUI;
   1.741              break;
   1.742 -        case SDLK_RMETA:
   1.743 -            keyboard->modstate |= KMOD_RMETA;
   1.744 +        case SDL_SCANCODE_RGUI:
   1.745 +            keyboard->modstate |= KMOD_RGUI;
   1.746              break;
   1.747 -        case SDLK_MODE:
   1.748 +        case SDL_SCANCODE_MODE:
   1.749              keyboard->modstate |= KMOD_MODE;
   1.750              break;
   1.751          default:
   1.752              break;
   1.753          }
   1.754      } else {
   1.755 -        switch (physicalKey) {
   1.756 -        case SDLK_UNKNOWN:
   1.757 +        switch (scancode) {
   1.758 +        case SDL_SCANCODE_NUMLOCKCLEAR:
   1.759 +        case SDL_SCANCODE_CAPSLOCK:
   1.760              break;
   1.761 -        case SDLK_KP_NUMLOCKCLEAR:
   1.762 -        case SDLK_CAPSLOCK:
   1.763 -            break;
   1.764 -        case SDLK_LCTRL:
   1.765 +        case SDL_SCANCODE_LCTRL:
   1.766              keyboard->modstate &= ~KMOD_LCTRL;
   1.767              break;
   1.768 -        case SDLK_RCTRL:
   1.769 +        case SDL_SCANCODE_RCTRL:
   1.770              keyboard->modstate &= ~KMOD_RCTRL;
   1.771              break;
   1.772 -        case SDLK_LSHIFT:
   1.773 +        case SDL_SCANCODE_LSHIFT:
   1.774              keyboard->modstate &= ~KMOD_LSHIFT;
   1.775              break;
   1.776 -        case SDLK_RSHIFT:
   1.777 +        case SDL_SCANCODE_RSHIFT:
   1.778              keyboard->modstate &= ~KMOD_RSHIFT;
   1.779              break;
   1.780 -        case SDLK_LALT:
   1.781 +        case SDL_SCANCODE_LALT:
   1.782              keyboard->modstate &= ~KMOD_LALT;
   1.783              break;
   1.784 -        case SDLK_RALT:
   1.785 +        case SDL_SCANCODE_RALT:
   1.786              keyboard->modstate &= ~KMOD_RALT;
   1.787              break;
   1.788 -        case SDLK_LMETA:
   1.789 -            keyboard->modstate &= ~KMOD_LMETA;
   1.790 +        case SDL_SCANCODE_LGUI:
   1.791 +            keyboard->modstate &= ~KMOD_LGUI;
   1.792              break;
   1.793 -        case SDLK_RMETA:
   1.794 -            keyboard->modstate &= ~KMOD_RMETA;
   1.795 +        case SDL_SCANCODE_RGUI:
   1.796 +            keyboard->modstate &= ~KMOD_RGUI;
   1.797              break;
   1.798 -        case SDLK_MODE:
   1.799 +        case SDL_SCANCODE_MODE:
   1.800              keyboard->modstate &= ~KMOD_MODE;
   1.801              break;
   1.802          default:
   1.803 @@ -475,18 +799,16 @@
   1.804          return 0;
   1.805      }
   1.806  
   1.807 -    if (physicalKey != SDLK_UNKNOWN) {
   1.808 -        /* Drop events that don't change state */
   1.809 -        if (keyboard->keystate[SDLK_INDEX(physicalKey)] == state) {
   1.810 +    /* Drop events that don't change state */
   1.811 +    if (keyboard->keystate[scancode] == state) {
   1.812  #if 0
   1.813 -            printf("Keyboard event didn't change state - dropped!\n");
   1.814 +        printf("Keyboard event didn't change state - dropped!\n");
   1.815  #endif
   1.816 -            return 0;
   1.817 -        }
   1.818 +        return 0;
   1.819 +    }
   1.820  
   1.821 -        /* Update internal keyboard state */
   1.822 -        keyboard->keystate[SDLK_INDEX(physicalKey)] = state;
   1.823 -    }
   1.824 +    /* Update internal keyboard state */
   1.825 +    keyboard->keystate[scancode] = state;
   1.826  
   1.827      /* Post the event, if desired */
   1.828      posted = 0;
   1.829 @@ -496,7 +818,7 @@
   1.830          event.key.which = (Uint8) index;
   1.831          event.key.state = state;
   1.832          event.key.keysym.scancode = scancode;
   1.833 -        event.key.keysym.sym = physicalKey;
   1.834 +        event.key.keysym.sym = keyboard->keymap[scancode];
   1.835          event.key.keysym.mod = modstate;
   1.836          event.key.keysym.unicode = 0;
   1.837          event.key.windowID = keyboard->focus;
   1.838 @@ -528,4 +850,138 @@
   1.839      return (posted);
   1.840  }
   1.841  
   1.842 +void
   1.843 +SDL_KeyboardQuit(void)
   1.844 +{
   1.845 +    int i;
   1.846 +
   1.847 +    for (i = 0; i < SDL_num_keyboards; ++i) {
   1.848 +        SDL_DelKeyboard(i);
   1.849 +    }
   1.850 +    SDL_num_keyboards = 0;
   1.851 +    SDL_current_keyboard = 0;
   1.852 +
   1.853 +    if (SDL_keyboards) {
   1.854 +        SDL_free(SDL_keyboards);
   1.855 +        SDL_keyboards = NULL;
   1.856 +    }
   1.857 +}
   1.858 +
   1.859 +int
   1.860 +SDL_GetNumKeyboards(void)
   1.861 +{
   1.862 +    return SDL_num_keyboards;
   1.863 +}
   1.864 +
   1.865 +int
   1.866 +SDL_SelectKeyboard(int index)
   1.867 +{
   1.868 +    if (index >= 0 && index < SDL_num_keyboards) {
   1.869 +        SDL_current_keyboard = index;
   1.870 +    }
   1.871 +    return SDL_current_keyboard;
   1.872 +}
   1.873 +
   1.874 +Uint8 *
   1.875 +SDL_GetKeyboardState(int *numkeys)
   1.876 +{
   1.877 +    SDL_Keyboard *keyboard = SDL_GetKeyboard(SDL_current_keyboard);
   1.878 +
   1.879 +    if (numkeys != (int *) 0) {
   1.880 +        *numkeys = SDL_NUM_SCANCODES;
   1.881 +    }
   1.882 +
   1.883 +    if (!keyboard) {
   1.884 +        return NULL;
   1.885 +    }
   1.886 +    return keyboard->keystate;
   1.887 +}
   1.888 +
   1.889 +SDLMod
   1.890 +SDL_GetModState(void)
   1.891 +{
   1.892 +    SDL_Keyboard *keyboard = SDL_GetKeyboard(SDL_current_keyboard);
   1.893 +
   1.894 +    if (!keyboard) {
   1.895 +        return KMOD_NONE;
   1.896 +    }
   1.897 +    return keyboard->modstate;
   1.898 +}
   1.899 +
   1.900 +void
   1.901 +SDL_SetModState(SDLMod modstate)
   1.902 +{
   1.903 +    SDL_Keyboard *keyboard = SDL_GetKeyboard(SDL_current_keyboard);
   1.904 +
   1.905 +    if (!keyboard) {
   1.906 +        return;
   1.907 +    }
   1.908 +    keyboard->modstate = modstate;
   1.909 +}
   1.910 +
   1.911 +SDLKey
   1.912 +SDL_GetKeyFromScancode(SDL_scancode scancode)
   1.913 +{
   1.914 +    SDL_Keyboard *keyboard = SDL_GetKeyboard(SDL_current_keyboard);
   1.915 +
   1.916 +    if (!keyboard) {
   1.917 +        return SDLK_UNKNOWN;
   1.918 +    }
   1.919 +    return keyboard->keymap[scancode];
   1.920 +}
   1.921 +
   1.922 +SDL_scancode
   1.923 +SDL_GetScancodeFromKey(SDLKey key)
   1.924 +{
   1.925 +    SDL_Keyboard *keyboard = SDL_GetKeyboard(SDL_current_keyboard);
   1.926 +    SDL_scancode scancode;
   1.927 +
   1.928 +    if (!keyboard) {
   1.929 +        return SDL_SCANCODE_UNKNOWN;
   1.930 +    }
   1.931 +
   1.932 +    for (scancode = SDL_SCANCODE_UNKNOWN; scancode < SDL_NUM_SCANCODES;
   1.933 +         ++scancode) {
   1.934 +        if (keyboard->keymap[scancode] == key) {
   1.935 +            return scancode;
   1.936 +        }
   1.937 +    }
   1.938 +    return SDL_SCANCODE_UNKNOWN;
   1.939 +}
   1.940 +
   1.941 +const char *
   1.942 +SDL_GetScancodeName(SDL_scancode scancode)
   1.943 +{
   1.944 +    const char *name = SDL_scancode_names[scancode];
   1.945 +
   1.946 +    if (name)
   1.947 +        return name;
   1.948 +    else
   1.949 +        return "";
   1.950 +}
   1.951 +
   1.952 +const char *
   1.953 +SDL_GetKeyName(SDLKey key)
   1.954 +{
   1.955 +    static char name[8];
   1.956 +    char *end;
   1.957 +
   1.958 +    if (key & SDLK_SCANCODE_MASK) {
   1.959 +        return
   1.960 +            SDL_GetScancodeName((SDL_scancode) (key & ~SDLK_SCANCODE_MASK));
   1.961 +    }
   1.962 +
   1.963 +    /* Unaccented letter keys on latin keyboards are normally
   1.964 +       labeled in upper case (and probably on others like Greek or
   1.965 +       Cyrillic too, so if you happen to know for sure, please
   1.966 +       adapt this). */
   1.967 +    if (key >= 'a' && key <= 'z') {
   1.968 +        key -= 32;
   1.969 +    }
   1.970 +
   1.971 +    end = SDL_UCS4ToUTF8((Uint32) key, name);
   1.972 +    *end = '\0';
   1.973 +    return name;
   1.974 +}
   1.975 +
   1.976  /* vi: set ts=4 sw=4 expandtab: */