src/events/SDL_keyboard.c
branchSDL-1.3
changeset 1673 624e1412fbba
parent 1670 eef792d31de8
child 1674 7688a73b25b1
     1.1 --- a/src/events/SDL_keyboard.c	Fri Jun 09 07:06:12 2006 +0000
     1.2 +++ b/src/events/SDL_keyboard.c	Sat Jun 10 09:11:59 2006 +0000
     1.3 @@ -29,307 +29,370 @@
     1.4  #include "SDL_sysevents.h"
     1.5  
     1.6  
     1.7 -/* Global keystate information */
     1.8 -static Uint8 SDL_KeyState[SDLK_LAST];
     1.9 -static SDLMod SDL_ModState;
    1.10 +/* Global keyboard information */
    1.11 +static int SDL_num_keyboards;
    1.12 +static int SDL_current_keyboard;
    1.13 +static SDL_Keyboard **SDL_keyboards;
    1.14  int SDL_TranslateUNICODE = 0;
    1.15  
    1.16 -static const char *keynames[SDLK_LAST]; /* Array of keycode names */
    1.17 -
    1.18 -/*
    1.19 - * jk 991215 - added
    1.20 - */
    1.21 -struct
    1.22 -{
    1.23 -    int firsttime;              /* if we check against the delay or repeat value */
    1.24 -    int delay;                  /* the delay before we start repeating */
    1.25 -    int interval;               /* the delay between key repeat events */
    1.26 -    Uint32 timestamp;           /* the time the first keydown event occurred */
    1.27 -
    1.28 -    SDL_Event evt;              /* the event we are supposed to repeat */
    1.29 -} SDL_KeyRepeat;
    1.30 +static const char *SDL_keynames[SDLK_LAST];     /* Array of keycode names */
    1.31  
    1.32  /* Public functions */
    1.33  int
    1.34  SDL_KeyboardInit(void)
    1.35  {
    1.36 -    SDL_VideoDevice *_this = SDL_GetVideoDevice();
    1.37 +    int i;
    1.38  
    1.39      /* Set default mode of UNICODE translation */
    1.40      SDL_EnableUNICODE(DEFAULT_UNICODE_TRANSLATION);
    1.41  
    1.42 -    /* Initialize the tables */
    1.43 -    SDL_ModState = KMOD_NONE;
    1.44 -    SDL_memset((void *) keynames, 0, sizeof(keynames));
    1.45 -    SDL_memset(SDL_KeyState, 0, sizeof(SDL_KeyState));
    1.46 -    _this->InitOSKeymap(_this);
    1.47 -
    1.48 +    /* Set default keyboard repeat setting */
    1.49      SDL_EnableKeyRepeat(0, 0);
    1.50  
    1.51 -    /* Fill in the blanks in keynames */
    1.52 -    keynames[SDLK_BACKSPACE] = "backspace";
    1.53 -    keynames[SDLK_TAB] = "tab";
    1.54 -    keynames[SDLK_CLEAR] = "clear";
    1.55 -    keynames[SDLK_RETURN] = "return";
    1.56 -    keynames[SDLK_PAUSE] = "pause";
    1.57 -    keynames[SDLK_ESCAPE] = "escape";
    1.58 -    keynames[SDLK_SPACE] = "space";
    1.59 -    keynames[SDLK_EXCLAIM] = "!";
    1.60 -    keynames[SDLK_QUOTEDBL] = "\"";
    1.61 -    keynames[SDLK_HASH] = "#";
    1.62 -    keynames[SDLK_DOLLAR] = "$";
    1.63 -    keynames[SDLK_AMPERSAND] = "&";
    1.64 -    keynames[SDLK_QUOTE] = "'";
    1.65 -    keynames[SDLK_LEFTPAREN] = "(";
    1.66 -    keynames[SDLK_RIGHTPAREN] = ")";
    1.67 -    keynames[SDLK_ASTERISK] = "*";
    1.68 -    keynames[SDLK_PLUS] = "+";
    1.69 -    keynames[SDLK_COMMA] = ",";
    1.70 -    keynames[SDLK_MINUS] = "-";
    1.71 -    keynames[SDLK_PERIOD] = ".";
    1.72 -    keynames[SDLK_SLASH] = "/";
    1.73 -    keynames[SDLK_0] = "0";
    1.74 -    keynames[SDLK_1] = "1";
    1.75 -    keynames[SDLK_2] = "2";
    1.76 -    keynames[SDLK_3] = "3";
    1.77 -    keynames[SDLK_4] = "4";
    1.78 -    keynames[SDLK_5] = "5";
    1.79 -    keynames[SDLK_6] = "6";
    1.80 -    keynames[SDLK_7] = "7";
    1.81 -    keynames[SDLK_8] = "8";
    1.82 -    keynames[SDLK_9] = "9";
    1.83 -    keynames[SDLK_COLON] = ":";
    1.84 -    keynames[SDLK_SEMICOLON] = ";";
    1.85 -    keynames[SDLK_LESS] = "<";
    1.86 -    keynames[SDLK_EQUALS] = "=";
    1.87 -    keynames[SDLK_GREATER] = ">";
    1.88 -    keynames[SDLK_QUESTION] = "?";
    1.89 -    keynames[SDLK_AT] = "@";
    1.90 -    keynames[SDLK_LEFTBRACKET] = "[";
    1.91 -    keynames[SDLK_BACKSLASH] = "\\";
    1.92 -    keynames[SDLK_RIGHTBRACKET] = "]";
    1.93 -    keynames[SDLK_CARET] = "^";
    1.94 -    keynames[SDLK_UNDERSCORE] = "_";
    1.95 -    keynames[SDLK_BACKQUOTE] = "`";
    1.96 -    keynames[SDLK_a] = "a";
    1.97 -    keynames[SDLK_b] = "b";
    1.98 -    keynames[SDLK_c] = "c";
    1.99 -    keynames[SDLK_d] = "d";
   1.100 -    keynames[SDLK_e] = "e";
   1.101 -    keynames[SDLK_f] = "f";
   1.102 -    keynames[SDLK_g] = "g";
   1.103 -    keynames[SDLK_h] = "h";
   1.104 -    keynames[SDLK_i] = "i";
   1.105 -    keynames[SDLK_j] = "j";
   1.106 -    keynames[SDLK_k] = "k";
   1.107 -    keynames[SDLK_l] = "l";
   1.108 -    keynames[SDLK_m] = "m";
   1.109 -    keynames[SDLK_n] = "n";
   1.110 -    keynames[SDLK_o] = "o";
   1.111 -    keynames[SDLK_p] = "p";
   1.112 -    keynames[SDLK_q] = "q";
   1.113 -    keynames[SDLK_r] = "r";
   1.114 -    keynames[SDLK_s] = "s";
   1.115 -    keynames[SDLK_t] = "t";
   1.116 -    keynames[SDLK_u] = "u";
   1.117 -    keynames[SDLK_v] = "v";
   1.118 -    keynames[SDLK_w] = "w";
   1.119 -    keynames[SDLK_x] = "x";
   1.120 -    keynames[SDLK_y] = "y";
   1.121 -    keynames[SDLK_z] = "z";
   1.122 -    keynames[SDLK_DELETE] = "delete";
   1.123 +    /* Initialize the tables */
   1.124 +    for (i = 0; i < SDL_arraysize(SDL_keynames); ++i) {
   1.125 +        switch (i) {
   1.126 +        case SDLK_BACKSPACE:
   1.127 +            SDL_keynames[i] = "backspace";
   1.128 +            break;
   1.129 +        case SDLK_TAB:
   1.130 +            SDL_keynames[i] = "tab";
   1.131 +            break;
   1.132 +        case SDLK_CLEAR:
   1.133 +            SDL_keynames[i] = "clear";
   1.134 +            break;
   1.135 +        case SDLK_RETURN:
   1.136 +            SDL_keynames[i] = "return";
   1.137 +            break;
   1.138 +        case SDLK_PAUSE:
   1.139 +            SDL_keynames[i] = "pause";
   1.140 +            break;
   1.141 +        case SDLK_ESCAPE:
   1.142 +            SDL_keynames[i] = "escape";
   1.143 +            break;
   1.144 +        case SDLK_SPACE:
   1.145 +            SDL_keynames[i] = "space";
   1.146 +            break;
   1.147  
   1.148 -    keynames[SDLK_WORLD_0] = "world 0";
   1.149 -    keynames[SDLK_WORLD_1] = "world 1";
   1.150 -    keynames[SDLK_WORLD_2] = "world 2";
   1.151 -    keynames[SDLK_WORLD_3] = "world 3";
   1.152 -    keynames[SDLK_WORLD_4] = "world 4";
   1.153 -    keynames[SDLK_WORLD_5] = "world 5";
   1.154 -    keynames[SDLK_WORLD_6] = "world 6";
   1.155 -    keynames[SDLK_WORLD_7] = "world 7";
   1.156 -    keynames[SDLK_WORLD_8] = "world 8";
   1.157 -    keynames[SDLK_WORLD_9] = "world 9";
   1.158 -    keynames[SDLK_WORLD_10] = "world 10";
   1.159 -    keynames[SDLK_WORLD_11] = "world 11";
   1.160 -    keynames[SDLK_WORLD_12] = "world 12";
   1.161 -    keynames[SDLK_WORLD_13] = "world 13";
   1.162 -    keynames[SDLK_WORLD_14] = "world 14";
   1.163 -    keynames[SDLK_WORLD_15] = "world 15";
   1.164 -    keynames[SDLK_WORLD_16] = "world 16";
   1.165 -    keynames[SDLK_WORLD_17] = "world 17";
   1.166 -    keynames[SDLK_WORLD_18] = "world 18";
   1.167 -    keynames[SDLK_WORLD_19] = "world 19";
   1.168 -    keynames[SDLK_WORLD_20] = "world 20";
   1.169 -    keynames[SDLK_WORLD_21] = "world 21";
   1.170 -    keynames[SDLK_WORLD_22] = "world 22";
   1.171 -    keynames[SDLK_WORLD_23] = "world 23";
   1.172 -    keynames[SDLK_WORLD_24] = "world 24";
   1.173 -    keynames[SDLK_WORLD_25] = "world 25";
   1.174 -    keynames[SDLK_WORLD_26] = "world 26";
   1.175 -    keynames[SDLK_WORLD_27] = "world 27";
   1.176 -    keynames[SDLK_WORLD_28] = "world 28";
   1.177 -    keynames[SDLK_WORLD_29] = "world 29";
   1.178 -    keynames[SDLK_WORLD_30] = "world 30";
   1.179 -    keynames[SDLK_WORLD_31] = "world 31";
   1.180 -    keynames[SDLK_WORLD_32] = "world 32";
   1.181 -    keynames[SDLK_WORLD_33] = "world 33";
   1.182 -    keynames[SDLK_WORLD_34] = "world 34";
   1.183 -    keynames[SDLK_WORLD_35] = "world 35";
   1.184 -    keynames[SDLK_WORLD_36] = "world 36";
   1.185 -    keynames[SDLK_WORLD_37] = "world 37";
   1.186 -    keynames[SDLK_WORLD_38] = "world 38";
   1.187 -    keynames[SDLK_WORLD_39] = "world 39";
   1.188 -    keynames[SDLK_WORLD_40] = "world 40";
   1.189 -    keynames[SDLK_WORLD_41] = "world 41";
   1.190 -    keynames[SDLK_WORLD_42] = "world 42";
   1.191 -    keynames[SDLK_WORLD_43] = "world 43";
   1.192 -    keynames[SDLK_WORLD_44] = "world 44";
   1.193 -    keynames[SDLK_WORLD_45] = "world 45";
   1.194 -    keynames[SDLK_WORLD_46] = "world 46";
   1.195 -    keynames[SDLK_WORLD_47] = "world 47";
   1.196 -    keynames[SDLK_WORLD_48] = "world 48";
   1.197 -    keynames[SDLK_WORLD_49] = "world 49";
   1.198 -    keynames[SDLK_WORLD_50] = "world 50";
   1.199 -    keynames[SDLK_WORLD_51] = "world 51";
   1.200 -    keynames[SDLK_WORLD_52] = "world 52";
   1.201 -    keynames[SDLK_WORLD_53] = "world 53";
   1.202 -    keynames[SDLK_WORLD_54] = "world 54";
   1.203 -    keynames[SDLK_WORLD_55] = "world 55";
   1.204 -    keynames[SDLK_WORLD_56] = "world 56";
   1.205 -    keynames[SDLK_WORLD_57] = "world 57";
   1.206 -    keynames[SDLK_WORLD_58] = "world 58";
   1.207 -    keynames[SDLK_WORLD_59] = "world 59";
   1.208 -    keynames[SDLK_WORLD_60] = "world 60";
   1.209 -    keynames[SDLK_WORLD_61] = "world 61";
   1.210 -    keynames[SDLK_WORLD_62] = "world 62";
   1.211 -    keynames[SDLK_WORLD_63] = "world 63";
   1.212 -    keynames[SDLK_WORLD_64] = "world 64";
   1.213 -    keynames[SDLK_WORLD_65] = "world 65";
   1.214 -    keynames[SDLK_WORLD_66] = "world 66";
   1.215 -    keynames[SDLK_WORLD_67] = "world 67";
   1.216 -    keynames[SDLK_WORLD_68] = "world 68";
   1.217 -    keynames[SDLK_WORLD_69] = "world 69";
   1.218 -    keynames[SDLK_WORLD_70] = "world 70";
   1.219 -    keynames[SDLK_WORLD_71] = "world 71";
   1.220 -    keynames[SDLK_WORLD_72] = "world 72";
   1.221 -    keynames[SDLK_WORLD_73] = "world 73";
   1.222 -    keynames[SDLK_WORLD_74] = "world 74";
   1.223 -    keynames[SDLK_WORLD_75] = "world 75";
   1.224 -    keynames[SDLK_WORLD_76] = "world 76";
   1.225 -    keynames[SDLK_WORLD_77] = "world 77";
   1.226 -    keynames[SDLK_WORLD_78] = "world 78";
   1.227 -    keynames[SDLK_WORLD_79] = "world 79";
   1.228 -    keynames[SDLK_WORLD_80] = "world 80";
   1.229 -    keynames[SDLK_WORLD_81] = "world 81";
   1.230 -    keynames[SDLK_WORLD_82] = "world 82";
   1.231 -    keynames[SDLK_WORLD_83] = "world 83";
   1.232 -    keynames[SDLK_WORLD_84] = "world 84";
   1.233 -    keynames[SDLK_WORLD_85] = "world 85";
   1.234 -    keynames[SDLK_WORLD_86] = "world 86";
   1.235 -    keynames[SDLK_WORLD_87] = "world 87";
   1.236 -    keynames[SDLK_WORLD_88] = "world 88";
   1.237 -    keynames[SDLK_WORLD_89] = "world 89";
   1.238 -    keynames[SDLK_WORLD_90] = "world 90";
   1.239 -    keynames[SDLK_WORLD_91] = "world 91";
   1.240 -    keynames[SDLK_WORLD_92] = "world 92";
   1.241 -    keynames[SDLK_WORLD_93] = "world 93";
   1.242 -    keynames[SDLK_WORLD_94] = "world 94";
   1.243 -    keynames[SDLK_WORLD_95] = "world 95";
   1.244 +        case SDLK_KP0:
   1.245 +            SDL_keynames[i] = "[0]";
   1.246 +            break;
   1.247 +        case SDLK_KP1:
   1.248 +            SDL_keynames[i] = "[1]";
   1.249 +            break;
   1.250 +        case SDLK_KP2:
   1.251 +            SDL_keynames[i] = "[2]";
   1.252 +            break;
   1.253 +        case SDLK_KP3:
   1.254 +            SDL_keynames[i] = "[3]";
   1.255 +            break;
   1.256 +        case SDLK_KP4:
   1.257 +            SDL_keynames[i] = "[4]";
   1.258 +            break;
   1.259 +        case SDLK_KP5:
   1.260 +            SDL_keynames[i] = "[5]";
   1.261 +            break;
   1.262 +        case SDLK_KP6:
   1.263 +            SDL_keynames[i] = "[6]";
   1.264 +            break;
   1.265 +        case SDLK_KP7:
   1.266 +            SDL_keynames[i] = "[7]";
   1.267 +            break;
   1.268 +        case SDLK_KP8:
   1.269 +            SDL_keynames[i] = "[8]";
   1.270 +            break;
   1.271 +        case SDLK_KP9:
   1.272 +            SDL_keynames[i] = "[9]";
   1.273 +            break;
   1.274 +        case SDLK_KP_PERIOD:
   1.275 +            SDL_keynames[i] = "[.]";
   1.276 +            break;
   1.277 +        case SDLK_KP_DIVIDE:
   1.278 +            SDL_keynames[i] = "[/]";
   1.279 +            break;
   1.280 +        case SDLK_KP_MULTIPLY:
   1.281 +            SDL_keynames[i] = "[*]";
   1.282 +            break;
   1.283 +        case SDLK_KP_MINUS:
   1.284 +            SDL_keynames[i] = "[-]";
   1.285 +            break;
   1.286 +        case SDLK_KP_PLUS:
   1.287 +            SDL_keynames[i] = "[+]";
   1.288 +            break;
   1.289 +        case SDLK_KP_ENTER:
   1.290 +            SDL_keynames[i] = "enter";
   1.291 +            break;
   1.292 +        case SDLK_KP_EQUALS:
   1.293 +            SDL_keynames[i] = "equals";
   1.294 +            break;
   1.295  
   1.296 -    keynames[SDLK_KP0] = "[0]";
   1.297 -    keynames[SDLK_KP1] = "[1]";
   1.298 -    keynames[SDLK_KP2] = "[2]";
   1.299 -    keynames[SDLK_KP3] = "[3]";
   1.300 -    keynames[SDLK_KP4] = "[4]";
   1.301 -    keynames[SDLK_KP5] = "[5]";
   1.302 -    keynames[SDLK_KP6] = "[6]";
   1.303 -    keynames[SDLK_KP7] = "[7]";
   1.304 -    keynames[SDLK_KP8] = "[8]";
   1.305 -    keynames[SDLK_KP9] = "[9]";
   1.306 -    keynames[SDLK_KP_PERIOD] = "[.]";
   1.307 -    keynames[SDLK_KP_DIVIDE] = "[/]";
   1.308 -    keynames[SDLK_KP_MULTIPLY] = "[*]";
   1.309 -    keynames[SDLK_KP_MINUS] = "[-]";
   1.310 -    keynames[SDLK_KP_PLUS] = "[+]";
   1.311 -    keynames[SDLK_KP_ENTER] = "enter";
   1.312 -    keynames[SDLK_KP_EQUALS] = "equals";
   1.313 +        case SDLK_UP:
   1.314 +            SDL_keynames[i] = "up";
   1.315 +            break;
   1.316 +        case SDLK_DOWN:
   1.317 +            SDL_keynames[i] = "down";
   1.318 +            break;
   1.319 +        case SDLK_RIGHT:
   1.320 +            SDL_keynames[i] = "right";
   1.321 +            break;
   1.322 +        case SDLK_LEFT:
   1.323 +            SDL_keynames[i] = "left";
   1.324 +            break;
   1.325 +        case SDLK_DOWN:
   1.326 +            SDL_keynames[i] = "down";
   1.327 +            break;
   1.328 +        case SDLK_INSERT:
   1.329 +            SDL_keynames[i] = "insert";
   1.330 +            break;
   1.331 +        case SDLK_HOME:
   1.332 +            SDL_keynames[i] = "home";
   1.333 +            break;
   1.334 +        case SDLK_END:
   1.335 +            SDL_keynames[i] = "end";
   1.336 +            break;
   1.337 +        case SDLK_PAGEUP:
   1.338 +            SDL_keynames[i] = "page up";
   1.339 +            break;
   1.340 +        case SDLK_PAGEDOWN:
   1.341 +            SDL_keynames[i] = "page down";
   1.342 +            break;
   1.343  
   1.344 -    keynames[SDLK_UP] = "up";
   1.345 -    keynames[SDLK_DOWN] = "down";
   1.346 -    keynames[SDLK_RIGHT] = "right";
   1.347 -    keynames[SDLK_LEFT] = "left";
   1.348 -    keynames[SDLK_DOWN] = "down";
   1.349 -    keynames[SDLK_INSERT] = "insert";
   1.350 -    keynames[SDLK_HOME] = "home";
   1.351 -    keynames[SDLK_END] = "end";
   1.352 -    keynames[SDLK_PAGEUP] = "page up";
   1.353 -    keynames[SDLK_PAGEDOWN] = "page down";
   1.354 +        case SDLK_F1:
   1.355 +            SDL_keynames[i] = "f1";
   1.356 +            break;
   1.357 +        case SDLK_F2:
   1.358 +            SDL_keynames[i] = "f2";
   1.359 +            break;
   1.360 +        case SDLK_F3:
   1.361 +            SDL_keynames[i] = "f3";
   1.362 +            break;
   1.363 +        case SDLK_F4:
   1.364 +            SDL_keynames[i] = "f4";
   1.365 +            break;
   1.366 +        case SDLK_F5:
   1.367 +            SDL_keynames[i] = "f5";
   1.368 +            break;
   1.369 +        case SDLK_F6:
   1.370 +            SDL_keynames[i] = "f6";
   1.371 +            break;
   1.372 +        case SDLK_F7:
   1.373 +            SDL_keynames[i] = "f7";
   1.374 +            break;
   1.375 +        case SDLK_F8:
   1.376 +            SDL_keynames[i] = "f8";
   1.377 +            break;
   1.378 +        case SDLK_F9:
   1.379 +            SDL_keynames[i] = "f9";
   1.380 +            break;
   1.381 +        case SDLK_F10:
   1.382 +            SDL_keynames[i] = "f10";
   1.383 +            break;
   1.384 +        case SDLK_F11:
   1.385 +            SDL_keynames[i] = "f11";
   1.386 +            break;
   1.387 +        case SDLK_F12:
   1.388 +            SDL_keynames[i] = "f12";
   1.389 +            break;
   1.390 +        case SDLK_F13:
   1.391 +            SDL_keynames[i] = "f13";
   1.392 +            break;
   1.393 +        case SDLK_F14:
   1.394 +            SDL_keynames[i] = "f14";
   1.395 +            break;
   1.396 +        case SDLK_F15:
   1.397 +            SDL_keynames[i] = "f15";
   1.398 +            break;
   1.399  
   1.400 -    keynames[SDLK_F1] = "f1";
   1.401 -    keynames[SDLK_F2] = "f2";
   1.402 -    keynames[SDLK_F3] = "f3";
   1.403 -    keynames[SDLK_F4] = "f4";
   1.404 -    keynames[SDLK_F5] = "f5";
   1.405 -    keynames[SDLK_F6] = "f6";
   1.406 -    keynames[SDLK_F7] = "f7";
   1.407 -    keynames[SDLK_F8] = "f8";
   1.408 -    keynames[SDLK_F9] = "f9";
   1.409 -    keynames[SDLK_F10] = "f10";
   1.410 -    keynames[SDLK_F11] = "f11";
   1.411 -    keynames[SDLK_F12] = "f12";
   1.412 -    keynames[SDLK_F13] = "f13";
   1.413 -    keynames[SDLK_F14] = "f14";
   1.414 -    keynames[SDLK_F15] = "f15";
   1.415 +        case SDLK_NUMLOCK:
   1.416 +            SDL_keynames[i] = "numlock";
   1.417 +            break;
   1.418 +        case SDLK_CAPSLOCK:
   1.419 +            SDL_keynames[i] = "caps lock";
   1.420 +            break;
   1.421 +        case SDLK_SCROLLOCK:
   1.422 +            SDL_keynames[i] = "scroll lock";
   1.423 +            break;
   1.424 +        case SDLK_RSHIFT:
   1.425 +            SDL_keynames[i] = "right shift";
   1.426 +            break;
   1.427 +        case SDLK_LSHIFT:
   1.428 +            SDL_keynames[i] = "left shift";
   1.429 +            break;
   1.430 +        case SDLK_RCTRL:
   1.431 +            SDL_keynames[i] = "right ctrl";
   1.432 +            break;
   1.433 +        case SDLK_LCTRL:
   1.434 +            SDL_keynames[i] = "left ctrl";
   1.435 +            break;
   1.436 +        case SDLK_RALT:
   1.437 +            SDL_keynames[i] = "right alt";
   1.438 +            break;
   1.439 +        case SDLK_LALT:
   1.440 +            SDL_keynames[i] = "left alt";
   1.441 +            break;
   1.442 +        case SDLK_RMETA:
   1.443 +            SDL_keynames[i] = "right meta";
   1.444 +            break;
   1.445 +        case SDLK_LMETA:
   1.446 +            SDL_keynames[i] = "left meta";
   1.447 +            break;
   1.448 +        case SDLK_LSUPER:
   1.449 +            SDL_keynames[i] = "left super";     /* "Windows" keys */
   1.450 +            break;
   1.451 +        case SDLK_RSUPER:
   1.452 +            SDL_keynames[i] = "right super";
   1.453 +            break;
   1.454 +        case SDLK_MODE:
   1.455 +            SDL_keynames[i] = "alt gr";
   1.456 +            break;
   1.457 +        case SDLK_COMPOSE:
   1.458 +            SDL_keynames[i] = "compose";
   1.459 +            break;
   1.460  
   1.461 -    keynames[SDLK_NUMLOCK] = "numlock";
   1.462 -    keynames[SDLK_CAPSLOCK] = "caps lock";
   1.463 -    keynames[SDLK_SCROLLOCK] = "scroll lock";
   1.464 -    keynames[SDLK_RSHIFT] = "right shift";
   1.465 -    keynames[SDLK_LSHIFT] = "left shift";
   1.466 -    keynames[SDLK_RCTRL] = "right ctrl";
   1.467 -    keynames[SDLK_LCTRL] = "left ctrl";
   1.468 -    keynames[SDLK_RALT] = "right alt";
   1.469 -    keynames[SDLK_LALT] = "left alt";
   1.470 -    keynames[SDLK_RMETA] = "right meta";
   1.471 -    keynames[SDLK_LMETA] = "left meta";
   1.472 -    keynames[SDLK_LSUPER] = "left super";       /* "Windows" keys */
   1.473 -    keynames[SDLK_RSUPER] = "right super";
   1.474 -    keynames[SDLK_MODE] = "alt gr";
   1.475 -    keynames[SDLK_COMPOSE] = "compose";
   1.476 +        case SDLK_HELP:
   1.477 +            SDL_keynames[i] = "help";
   1.478 +            break;
   1.479 +        case SDLK_PRINT:
   1.480 +            SDL_keynames[i] = "print screen";
   1.481 +            break;
   1.482 +        case SDLK_SYSREQ:
   1.483 +            SDL_keynames[i] = "sys req";
   1.484 +            break;
   1.485 +        case SDLK_BREAK:
   1.486 +            SDL_keynames[i] = "break";
   1.487 +            break;
   1.488 +        case SDLK_MENU:
   1.489 +            SDL_keynames[i] = "menu";
   1.490 +            break;
   1.491 +        case SDLK_POWER:
   1.492 +            SDL_keynames[i] = "power";
   1.493 +            break;
   1.494 +        case SDLK_EURO:
   1.495 +            SDL_keynames[i] = "euro";
   1.496 +            break;
   1.497 +        case SDLK_UNDO:
   1.498 +            SDL_keynames[i] = "undo";
   1.499 +            break;
   1.500  
   1.501 -    keynames[SDLK_HELP] = "help";
   1.502 -    keynames[SDLK_PRINT] = "print screen";
   1.503 -    keynames[SDLK_SYSREQ] = "sys req";
   1.504 -    keynames[SDLK_BREAK] = "break";
   1.505 -    keynames[SDLK_MENU] = "menu";
   1.506 -    keynames[SDLK_POWER] = "power";
   1.507 -    keynames[SDLK_EURO] = "euro";
   1.508 -    keynames[SDLK_UNDO] = "undo";
   1.509 +        default:
   1.510 +            SDL_keynames[i] = NULL;
   1.511 +            break;
   1.512 +        }
   1.513 +    }
   1.514  
   1.515      /* Done.  Whew. */
   1.516      return (0);
   1.517  }
   1.518  
   1.519 +SDL_Keyboard *
   1.520 +SDL_GetKeyboard(int index)
   1.521 +{
   1.522 +    if (index < 0 || index >= SDL_num_keyboards) {
   1.523 +        return NULL;
   1.524 +    }
   1.525 +    return SDL_keyboards[index];
   1.526 +}
   1.527 +
   1.528 +int
   1.529 +SDL_AddKeyboard(const SDL_Keyboard * keyboard, int index)
   1.530 +{
   1.531 +    SDL_Keyboard **keyboards;
   1.532 +    SDL_Cursor *cursor;
   1.533 +    int selected_keyboard;
   1.534 +
   1.535 +    /* Add the keyboard to the list of keyboards */
   1.536 +    if (index < 0 || index >= SDL_num_keyboards || SDL_keyboards[index]) {
   1.537 +        keyboards =
   1.538 +            (SDL_Keyboard **) SDL_realloc(SDL_keyboards,
   1.539 +                                          (SDL_num_keyboards +
   1.540 +                                           1) * sizeof(*keyboards));
   1.541 +        if (!keyboards) {
   1.542 +            SDL_OutOfMemory();
   1.543 +            return -1;
   1.544 +        }
   1.545 +
   1.546 +        SDL_keyboards = keyboards;
   1.547 +        index = SDL_num_keyboards++;
   1.548 +    }
   1.549 +    SDL_keyboards[index] =
   1.550 +        (SDL_Keyboard *) SDL_malloc(sizeof(*SDL_keyboards[index]));
   1.551 +    if (!SDL_keyboards[index]) {
   1.552 +        SDL_OutOfMemory();
   1.553 +        return -1;
   1.554 +    }
   1.555 +    *SDL_keyboards[index] = *keyboard;
   1.556 +
   1.557 +    return index;
   1.558 +}
   1.559 +
   1.560 +void
   1.561 +SDL_DelKeyboard(int index)
   1.562 +{
   1.563 +    SDL_Keyboard *keyboard = SDL_GetKeyboard(index);
   1.564 +
   1.565 +    if (!keyboard) {
   1.566 +        return;
   1.567 +    }
   1.568 +
   1.569 +    if (keyboard->FreeKeyboard) {
   1.570 +        keyboard->FreeKeyboard(keyboard);
   1.571 +    }
   1.572 +    SDL_free(keyboard);
   1.573 +
   1.574 +    SDL_keyboards[index] = NULL;
   1.575 +}
   1.576 +
   1.577 +void
   1.578 +SDL_ResetKeyboard(int index)
   1.579 +{
   1.580 +    SDL_Keyboard *keyboard = SDL_GetKeyboard(index);
   1.581 +    SDL_keysym keysym;
   1.582 +    SDLKey key;
   1.583 +
   1.584 +    if (!keyboard) {
   1.585 +        return;
   1.586 +    }
   1.587 +
   1.588 +    SDL_memset(&keysym, 0, (sizeof keysym));
   1.589 +    for (key = SDLK_FIRST; key < SDLK_LAST; ++key) {
   1.590 +        if (keyboard->keystate[key] == SDL_PRESSED) {
   1.591 +            keysym.sym = key;
   1.592 +            SDL_SendKeyboardKey(index, SDL_RELEASED, &keysym);
   1.593 +        }
   1.594 +    }
   1.595 +    keyboard->keyrepeat.timestamp = 0;
   1.596 +}
   1.597 +
   1.598  void
   1.599  SDL_KeyboardQuit(void)
   1.600  {
   1.601 +    int i;
   1.602 +
   1.603 +    for (i = 0; i < SDL_num_keyboards; ++i) {
   1.604 +        SDL_DelKeyboard(i);
   1.605 +    }
   1.606 +    SDL_num_keyboards = 0;
   1.607 +    SDL_current_keyboard = 0;
   1.608 +
   1.609 +    if (SDL_keyboards) {
   1.610 +        SDL_free(SDL_keyboards);
   1.611 +        SDL_keyboards = NULL;
   1.612 +    }
   1.613  }
   1.614  
   1.615 -/* We lost the keyboard, so post key up messages for all pressed keys */
   1.616 -void
   1.617 -SDL_ResetKeyboard(void)
   1.618 +int
   1.619 +SDL_GetNumKeyboards(void)
   1.620  {
   1.621 -    SDL_keysym keysym;
   1.622 -    SDLKey key;
   1.623 +    return SDL_num_keyboards;
   1.624 +}
   1.625  
   1.626 -    SDL_memset(&keysym, 0, (sizeof keysym));
   1.627 -    for (key = SDLK_FIRST; key < SDLK_LAST; ++key) {
   1.628 -        if (SDL_KeyState[key] == SDL_PRESSED) {
   1.629 -            keysym.sym = key;
   1.630 -            SDL_SendKeyboard(SDL_RELEASED, &keysym);
   1.631 -        }
   1.632 +int
   1.633 +SDL_SelectKeyboard(int index)
   1.634 +{
   1.635 +    if (index >= 0 && index < SDL_num_keyboards) {
   1.636 +        SDL_current_keyboard = index;
   1.637      }
   1.638 -    SDL_KeyRepeat.timestamp = 0;
   1.639 +    return SDL_current_keyboard;
   1.640  }
   1.641  
   1.642  int
   1.643 @@ -355,34 +418,45 @@
   1.644  SDLMod
   1.645  SDL_GetModState(void)
   1.646  {
   1.647 -    return (SDL_ModState);
   1.648 +    SDL_Keyboard *keyboard = SDL_GetKeyboard(index);
   1.649 +
   1.650 +    if (!keyboard) {
   1.651 +        return KMOD_NONE;
   1.652 +    }
   1.653 +    return keyboard->modstate;
   1.654  }
   1.655  
   1.656  void
   1.657  SDL_SetModState(SDLMod modstate)
   1.658  {
   1.659 -    SDL_ModState = modstate;
   1.660 +    SDL_Keyboard *keyboard = SDL_GetKeyboard(index);
   1.661 +
   1.662 +    if (!keyboard) {
   1.663 +        return;
   1.664 +    }
   1.665 +    keyboard->modstate = modstate;
   1.666  }
   1.667  
   1.668 -char *
   1.669 +const char *
   1.670  SDL_GetKeyName(SDLKey key)
   1.671  {
   1.672      const char *keyname;
   1.673  
   1.674 -    keyname = NULL;
   1.675 -    if (key < SDLK_LAST) {
   1.676 -        keyname = keynames[key];
   1.677 +    keyname = keynames[key];
   1.678 +    if (keyname == NULL) {
   1.679 +        if (key < 256) {
   1.680 +            static char temp[4];
   1.681 +          FIXME:Convert to UTF - 8 keyname = temp;
   1.682 +        } else {
   1.683 +            keyname = "unknown key";
   1.684 +        }
   1.685      }
   1.686 -    if (keyname == NULL) {
   1.687 -        keyname = "unknown key";
   1.688 -    }
   1.689 -    /* FIXME: make this function const in 1.3 */
   1.690 -    return (char *) (keyname);
   1.691 +    return keyname;
   1.692  }
   1.693  
   1.694  /* These are global for SDL_eventloop.c */
   1.695  int
   1.696 -SDL_SendKeyboard(Uint8 state, SDL_keysym * keysym)
   1.697 +SDL_SendKeyboardKey(int index, Uint8 state, const SDL_keysym * keysym)
   1.698  {
   1.699      SDL_Event event;
   1.700      int posted, repeatable;