src/events/SDL_keyboard.c
changeset 1895 c121d94672cb
parent 1760 a9be6a3a51d1
child 1959 25d6537feea4
     1.1 --- a/src/events/SDL_keyboard.c	Thu Jul 06 18:01:37 2006 +0000
     1.2 +++ b/src/events/SDL_keyboard.c	Mon Jul 10 21:04:37 2006 +0000
     1.3 @@ -29,550 +29,749 @@
     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  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 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 -	int firsttime;    /* if we check against the delay or repeat value */
    1.23 -	int delay;        /* the delay before we start repeating */
    1.24 -	int interval;     /* the delay between key repeat events */
    1.25 -	Uint32 timestamp; /* the time the first keydown event occurred */
    1.26 -
    1.27 -	SDL_Event evt;    /* the event we are supposed to repeat */
    1.28 -} SDL_KeyRepeat;
    1.29 +static const char *SDL_keynames[SDLK_LAST];     /* Array of keycode names */
    1.30  
    1.31  /* Public functions */
    1.32 -int SDL_KeyboardInit(void)
    1.33 +int
    1.34 +SDL_KeyboardInit(void)
    1.35  {
    1.36 -	SDL_VideoDevice *video = current_video;
    1.37 -	SDL_VideoDevice *this  = current_video;
    1.38 +    int i;
    1.39  
    1.40 -	/* Set default mode of UNICODE translation */
    1.41 -	SDL_EnableUNICODE(DEFAULT_UNICODE_TRANSLATION);
    1.42 +    /* Set default mode of UNICODE translation */
    1.43 +    SDL_EnableUNICODE(DEFAULT_UNICODE_TRANSLATION);
    1.44  
    1.45 -	/* Initialize the tables */
    1.46 -	SDL_ModState = KMOD_NONE;
    1.47 -	SDL_memset((void*)keynames, 0, sizeof(keynames));
    1.48 -	SDL_memset(SDL_KeyState, 0, sizeof(SDL_KeyState));
    1.49 -	video->InitOSKeymap(this);
    1.50 +    /* Initialize the tables */
    1.51 +    for (i = 0; i < SDL_arraysize(SDL_keynames); ++i) {
    1.52 +        switch (i) {
    1.53 +        case SDLK_BACKSPACE:
    1.54 +            SDL_keynames[i] = "backspace";
    1.55 +            break;
    1.56 +        case SDLK_TAB:
    1.57 +            SDL_keynames[i] = "tab";
    1.58 +            break;
    1.59 +        case SDLK_CLEAR:
    1.60 +            SDL_keynames[i] = "clear";
    1.61 +            break;
    1.62 +        case SDLK_RETURN:
    1.63 +            SDL_keynames[i] = "return";
    1.64 +            break;
    1.65 +        case SDLK_PAUSE:
    1.66 +            SDL_keynames[i] = "pause";
    1.67 +            break;
    1.68 +        case SDLK_ESCAPE:
    1.69 +            SDL_keynames[i] = "escape";
    1.70 +            break;
    1.71 +        case SDLK_SPACE:
    1.72 +            SDL_keynames[i] = "space";
    1.73 +            break;
    1.74  
    1.75 -	SDL_EnableKeyRepeat(0, 0);
    1.76 +        case SDLK_KP0:
    1.77 +            SDL_keynames[i] = "[0]";
    1.78 +            break;
    1.79 +        case SDLK_KP1:
    1.80 +            SDL_keynames[i] = "[1]";
    1.81 +            break;
    1.82 +        case SDLK_KP2:
    1.83 +            SDL_keynames[i] = "[2]";
    1.84 +            break;
    1.85 +        case SDLK_KP3:
    1.86 +            SDL_keynames[i] = "[3]";
    1.87 +            break;
    1.88 +        case SDLK_KP4:
    1.89 +            SDL_keynames[i] = "[4]";
    1.90 +            break;
    1.91 +        case SDLK_KP5:
    1.92 +            SDL_keynames[i] = "[5]";
    1.93 +            break;
    1.94 +        case SDLK_KP6:
    1.95 +            SDL_keynames[i] = "[6]";
    1.96 +            break;
    1.97 +        case SDLK_KP7:
    1.98 +            SDL_keynames[i] = "[7]";
    1.99 +            break;
   1.100 +        case SDLK_KP8:
   1.101 +            SDL_keynames[i] = "[8]";
   1.102 +            break;
   1.103 +        case SDLK_KP9:
   1.104 +            SDL_keynames[i] = "[9]";
   1.105 +            break;
   1.106 +        case SDLK_KP_PERIOD:
   1.107 +            SDL_keynames[i] = "[.]";
   1.108 +            break;
   1.109 +        case SDLK_KP_DIVIDE:
   1.110 +            SDL_keynames[i] = "[/]";
   1.111 +            break;
   1.112 +        case SDLK_KP_MULTIPLY:
   1.113 +            SDL_keynames[i] = "[*]";
   1.114 +            break;
   1.115 +        case SDLK_KP_MINUS:
   1.116 +            SDL_keynames[i] = "[-]";
   1.117 +            break;
   1.118 +        case SDLK_KP_PLUS:
   1.119 +            SDL_keynames[i] = "[+]";
   1.120 +            break;
   1.121 +        case SDLK_KP_ENTER:
   1.122 +            SDL_keynames[i] = "enter";
   1.123 +            break;
   1.124 +        case SDLK_KP_EQUALS:
   1.125 +            SDL_keynames[i] = "equals";
   1.126 +            break;
   1.127  
   1.128 -	/* Fill in the blanks in keynames */
   1.129 -	keynames[SDLK_BACKSPACE] = "backspace";
   1.130 -	keynames[SDLK_TAB] = "tab";
   1.131 -	keynames[SDLK_CLEAR] = "clear";
   1.132 -	keynames[SDLK_RETURN] = "return";
   1.133 -	keynames[SDLK_PAUSE] = "pause";
   1.134 -	keynames[SDLK_ESCAPE] = "escape";
   1.135 -	keynames[SDLK_SPACE] = "space";
   1.136 -	keynames[SDLK_EXCLAIM]  = "!";
   1.137 -	keynames[SDLK_QUOTEDBL]  = "\"";
   1.138 -	keynames[SDLK_HASH]  = "#";
   1.139 -	keynames[SDLK_DOLLAR]  = "$";
   1.140 -	keynames[SDLK_AMPERSAND]  = "&";
   1.141 -	keynames[SDLK_QUOTE] = "'";
   1.142 -	keynames[SDLK_LEFTPAREN] = "(";
   1.143 -	keynames[SDLK_RIGHTPAREN] = ")";
   1.144 -	keynames[SDLK_ASTERISK] = "*";
   1.145 -	keynames[SDLK_PLUS] = "+";
   1.146 -	keynames[SDLK_COMMA] = ",";
   1.147 -	keynames[SDLK_MINUS] = "-";
   1.148 -	keynames[SDLK_PERIOD] = ".";
   1.149 -	keynames[SDLK_SLASH] = "/";
   1.150 -	keynames[SDLK_0] = "0";
   1.151 -	keynames[SDLK_1] = "1";
   1.152 -	keynames[SDLK_2] = "2";
   1.153 -	keynames[SDLK_3] = "3";
   1.154 -	keynames[SDLK_4] = "4";
   1.155 -	keynames[SDLK_5] = "5";
   1.156 -	keynames[SDLK_6] = "6";
   1.157 -	keynames[SDLK_7] = "7";
   1.158 -	keynames[SDLK_8] = "8";
   1.159 -	keynames[SDLK_9] = "9";
   1.160 -	keynames[SDLK_COLON] = ":";
   1.161 -	keynames[SDLK_SEMICOLON] = ";";
   1.162 -	keynames[SDLK_LESS] = "<";
   1.163 -	keynames[SDLK_EQUALS] = "=";
   1.164 -	keynames[SDLK_GREATER] = ">";
   1.165 -	keynames[SDLK_QUESTION] = "?";
   1.166 -	keynames[SDLK_AT] = "@";
   1.167 -	keynames[SDLK_LEFTBRACKET] = "[";
   1.168 -	keynames[SDLK_BACKSLASH] = "\\";
   1.169 -	keynames[SDLK_RIGHTBRACKET] = "]";
   1.170 -	keynames[SDLK_CARET] = "^";
   1.171 -	keynames[SDLK_UNDERSCORE] = "_";
   1.172 -	keynames[SDLK_BACKQUOTE] = "`";
   1.173 -	keynames[SDLK_a] = "a";
   1.174 -	keynames[SDLK_b] = "b";
   1.175 -	keynames[SDLK_c] = "c";
   1.176 -	keynames[SDLK_d] = "d";
   1.177 -	keynames[SDLK_e] = "e";
   1.178 -	keynames[SDLK_f] = "f";
   1.179 -	keynames[SDLK_g] = "g";
   1.180 -	keynames[SDLK_h] = "h";
   1.181 -	keynames[SDLK_i] = "i";
   1.182 -	keynames[SDLK_j] = "j";
   1.183 -	keynames[SDLK_k] = "k";
   1.184 -	keynames[SDLK_l] = "l";
   1.185 -	keynames[SDLK_m] = "m";
   1.186 -	keynames[SDLK_n] = "n";
   1.187 -	keynames[SDLK_o] = "o";
   1.188 -	keynames[SDLK_p] = "p";
   1.189 -	keynames[SDLK_q] = "q";
   1.190 -	keynames[SDLK_r] = "r";
   1.191 -	keynames[SDLK_s] = "s";
   1.192 -	keynames[SDLK_t] = "t";
   1.193 -	keynames[SDLK_u] = "u";
   1.194 -	keynames[SDLK_v] = "v";
   1.195 -	keynames[SDLK_w] = "w";
   1.196 -	keynames[SDLK_x] = "x";
   1.197 -	keynames[SDLK_y] = "y";
   1.198 -	keynames[SDLK_z] = "z";
   1.199 -	keynames[SDLK_DELETE] = "delete";
   1.200 +        case SDLK_UP:
   1.201 +            SDL_keynames[i] = "up";
   1.202 +            break;
   1.203 +        case SDLK_DOWN:
   1.204 +            SDL_keynames[i] = "down";
   1.205 +            break;
   1.206 +        case SDLK_RIGHT:
   1.207 +            SDL_keynames[i] = "right";
   1.208 +            break;
   1.209 +        case SDLK_LEFT:
   1.210 +            SDL_keynames[i] = "left";
   1.211 +            break;
   1.212 +        case SDLK_INSERT:
   1.213 +            SDL_keynames[i] = "insert";
   1.214 +            break;
   1.215 +        case SDLK_HOME:
   1.216 +            SDL_keynames[i] = "home";
   1.217 +            break;
   1.218 +        case SDLK_END:
   1.219 +            SDL_keynames[i] = "end";
   1.220 +            break;
   1.221 +        case SDLK_PAGEUP:
   1.222 +            SDL_keynames[i] = "page up";
   1.223 +            break;
   1.224 +        case SDLK_PAGEDOWN:
   1.225 +            SDL_keynames[i] = "page down";
   1.226 +            break;
   1.227  
   1.228 -	keynames[SDLK_WORLD_0] = "world 0";
   1.229 -	keynames[SDLK_WORLD_1] = "world 1";
   1.230 -	keynames[SDLK_WORLD_2] = "world 2";
   1.231 -	keynames[SDLK_WORLD_3] = "world 3";
   1.232 -	keynames[SDLK_WORLD_4] = "world 4";
   1.233 -	keynames[SDLK_WORLD_5] = "world 5";
   1.234 -	keynames[SDLK_WORLD_6] = "world 6";
   1.235 -	keynames[SDLK_WORLD_7] = "world 7";
   1.236 -	keynames[SDLK_WORLD_8] = "world 8";
   1.237 -	keynames[SDLK_WORLD_9] = "world 9";
   1.238 -	keynames[SDLK_WORLD_10] = "world 10";
   1.239 -	keynames[SDLK_WORLD_11] = "world 11";
   1.240 -	keynames[SDLK_WORLD_12] = "world 12";
   1.241 -	keynames[SDLK_WORLD_13] = "world 13";
   1.242 -	keynames[SDLK_WORLD_14] = "world 14";
   1.243 -	keynames[SDLK_WORLD_15] = "world 15";
   1.244 -	keynames[SDLK_WORLD_16] = "world 16";
   1.245 -	keynames[SDLK_WORLD_17] = "world 17";
   1.246 -	keynames[SDLK_WORLD_18] = "world 18";
   1.247 -	keynames[SDLK_WORLD_19] = "world 19";
   1.248 -	keynames[SDLK_WORLD_20] = "world 20";
   1.249 -	keynames[SDLK_WORLD_21] = "world 21";
   1.250 -	keynames[SDLK_WORLD_22] = "world 22";
   1.251 -	keynames[SDLK_WORLD_23] = "world 23";
   1.252 -	keynames[SDLK_WORLD_24] = "world 24";
   1.253 -	keynames[SDLK_WORLD_25] = "world 25";
   1.254 -	keynames[SDLK_WORLD_26] = "world 26";
   1.255 -	keynames[SDLK_WORLD_27] = "world 27";
   1.256 -	keynames[SDLK_WORLD_28] = "world 28";
   1.257 -	keynames[SDLK_WORLD_29] = "world 29";
   1.258 -	keynames[SDLK_WORLD_30] = "world 30";
   1.259 -	keynames[SDLK_WORLD_31] = "world 31";
   1.260 -	keynames[SDLK_WORLD_32] = "world 32";
   1.261 -	keynames[SDLK_WORLD_33] = "world 33";
   1.262 -	keynames[SDLK_WORLD_34] = "world 34";
   1.263 -	keynames[SDLK_WORLD_35] = "world 35";
   1.264 -	keynames[SDLK_WORLD_36] = "world 36";
   1.265 -	keynames[SDLK_WORLD_37] = "world 37";
   1.266 -	keynames[SDLK_WORLD_38] = "world 38";
   1.267 -	keynames[SDLK_WORLD_39] = "world 39";
   1.268 -	keynames[SDLK_WORLD_40] = "world 40";
   1.269 -	keynames[SDLK_WORLD_41] = "world 41";
   1.270 -	keynames[SDLK_WORLD_42] = "world 42";
   1.271 -	keynames[SDLK_WORLD_43] = "world 43";
   1.272 -	keynames[SDLK_WORLD_44] = "world 44";
   1.273 -	keynames[SDLK_WORLD_45] = "world 45";
   1.274 -	keynames[SDLK_WORLD_46] = "world 46";
   1.275 -	keynames[SDLK_WORLD_47] = "world 47";
   1.276 -	keynames[SDLK_WORLD_48] = "world 48";
   1.277 -	keynames[SDLK_WORLD_49] = "world 49";
   1.278 -	keynames[SDLK_WORLD_50] = "world 50";
   1.279 -	keynames[SDLK_WORLD_51] = "world 51";
   1.280 -	keynames[SDLK_WORLD_52] = "world 52";
   1.281 -	keynames[SDLK_WORLD_53] = "world 53";
   1.282 -	keynames[SDLK_WORLD_54] = "world 54";
   1.283 -	keynames[SDLK_WORLD_55] = "world 55";
   1.284 -	keynames[SDLK_WORLD_56] = "world 56";
   1.285 -	keynames[SDLK_WORLD_57] = "world 57";
   1.286 -	keynames[SDLK_WORLD_58] = "world 58";
   1.287 -	keynames[SDLK_WORLD_59] = "world 59";
   1.288 -	keynames[SDLK_WORLD_60] = "world 60";
   1.289 -	keynames[SDLK_WORLD_61] = "world 61";
   1.290 -	keynames[SDLK_WORLD_62] = "world 62";
   1.291 -	keynames[SDLK_WORLD_63] = "world 63";
   1.292 -	keynames[SDLK_WORLD_64] = "world 64";
   1.293 -	keynames[SDLK_WORLD_65] = "world 65";
   1.294 -	keynames[SDLK_WORLD_66] = "world 66";
   1.295 -	keynames[SDLK_WORLD_67] = "world 67";
   1.296 -	keynames[SDLK_WORLD_68] = "world 68";
   1.297 -	keynames[SDLK_WORLD_69] = "world 69";
   1.298 -	keynames[SDLK_WORLD_70] = "world 70";
   1.299 -	keynames[SDLK_WORLD_71] = "world 71";
   1.300 -	keynames[SDLK_WORLD_72] = "world 72";
   1.301 -	keynames[SDLK_WORLD_73] = "world 73";
   1.302 -	keynames[SDLK_WORLD_74] = "world 74";
   1.303 -	keynames[SDLK_WORLD_75] = "world 75";
   1.304 -	keynames[SDLK_WORLD_76] = "world 76";
   1.305 -	keynames[SDLK_WORLD_77] = "world 77";
   1.306 -	keynames[SDLK_WORLD_78] = "world 78";
   1.307 -	keynames[SDLK_WORLD_79] = "world 79";
   1.308 -	keynames[SDLK_WORLD_80] = "world 80";
   1.309 -	keynames[SDLK_WORLD_81] = "world 81";
   1.310 -	keynames[SDLK_WORLD_82] = "world 82";
   1.311 -	keynames[SDLK_WORLD_83] = "world 83";
   1.312 -	keynames[SDLK_WORLD_84] = "world 84";
   1.313 -	keynames[SDLK_WORLD_85] = "world 85";
   1.314 -	keynames[SDLK_WORLD_86] = "world 86";
   1.315 -	keynames[SDLK_WORLD_87] = "world 87";
   1.316 -	keynames[SDLK_WORLD_88] = "world 88";
   1.317 -	keynames[SDLK_WORLD_89] = "world 89";
   1.318 -	keynames[SDLK_WORLD_90] = "world 90";
   1.319 -	keynames[SDLK_WORLD_91] = "world 91";
   1.320 -	keynames[SDLK_WORLD_92] = "world 92";
   1.321 -	keynames[SDLK_WORLD_93] = "world 93";
   1.322 -	keynames[SDLK_WORLD_94] = "world 94";
   1.323 -	keynames[SDLK_WORLD_95] = "world 95";
   1.324 +        case SDLK_F1:
   1.325 +            SDL_keynames[i] = "f1";
   1.326 +            break;
   1.327 +        case SDLK_F2:
   1.328 +            SDL_keynames[i] = "f2";
   1.329 +            break;
   1.330 +        case SDLK_F3:
   1.331 +            SDL_keynames[i] = "f3";
   1.332 +            break;
   1.333 +        case SDLK_F4:
   1.334 +            SDL_keynames[i] = "f4";
   1.335 +            break;
   1.336 +        case SDLK_F5:
   1.337 +            SDL_keynames[i] = "f5";
   1.338 +            break;
   1.339 +        case SDLK_F6:
   1.340 +            SDL_keynames[i] = "f6";
   1.341 +            break;
   1.342 +        case SDLK_F7:
   1.343 +            SDL_keynames[i] = "f7";
   1.344 +            break;
   1.345 +        case SDLK_F8:
   1.346 +            SDL_keynames[i] = "f8";
   1.347 +            break;
   1.348 +        case SDLK_F9:
   1.349 +            SDL_keynames[i] = "f9";
   1.350 +            break;
   1.351 +        case SDLK_F10:
   1.352 +            SDL_keynames[i] = "f10";
   1.353 +            break;
   1.354 +        case SDLK_F11:
   1.355 +            SDL_keynames[i] = "f11";
   1.356 +            break;
   1.357 +        case SDLK_F12:
   1.358 +            SDL_keynames[i] = "f12";
   1.359 +            break;
   1.360 +        case SDLK_F13:
   1.361 +            SDL_keynames[i] = "f13";
   1.362 +            break;
   1.363 +        case SDLK_F14:
   1.364 +            SDL_keynames[i] = "f14";
   1.365 +            break;
   1.366 +        case SDLK_F15:
   1.367 +            SDL_keynames[i] = "f15";
   1.368 +            break;
   1.369  
   1.370 -	keynames[SDLK_KP0] = "[0]";
   1.371 -	keynames[SDLK_KP1] = "[1]";
   1.372 -	keynames[SDLK_KP2] = "[2]";
   1.373 -	keynames[SDLK_KP3] = "[3]";
   1.374 -	keynames[SDLK_KP4] = "[4]";
   1.375 -	keynames[SDLK_KP5] = "[5]";
   1.376 -	keynames[SDLK_KP6] = "[6]";
   1.377 -	keynames[SDLK_KP7] = "[7]";
   1.378 -	keynames[SDLK_KP8] = "[8]";
   1.379 -	keynames[SDLK_KP9] = "[9]";
   1.380 -	keynames[SDLK_KP_PERIOD] = "[.]";
   1.381 -	keynames[SDLK_KP_DIVIDE] = "[/]";
   1.382 -	keynames[SDLK_KP_MULTIPLY] = "[*]";
   1.383 -	keynames[SDLK_KP_MINUS] = "[-]";
   1.384 -	keynames[SDLK_KP_PLUS] = "[+]";
   1.385 -	keynames[SDLK_KP_ENTER] = "enter";
   1.386 -	keynames[SDLK_KP_EQUALS] = "equals";
   1.387 +        case SDLK_NUMLOCK:
   1.388 +            SDL_keynames[i] = "numlock";
   1.389 +            break;
   1.390 +        case SDLK_CAPSLOCK:
   1.391 +            SDL_keynames[i] = "caps lock";
   1.392 +            break;
   1.393 +        case SDLK_SCROLLOCK:
   1.394 +            SDL_keynames[i] = "scroll lock";
   1.395 +            break;
   1.396 +        case SDLK_RSHIFT:
   1.397 +            SDL_keynames[i] = "right shift";
   1.398 +            break;
   1.399 +        case SDLK_LSHIFT:
   1.400 +            SDL_keynames[i] = "left shift";
   1.401 +            break;
   1.402 +        case SDLK_RCTRL:
   1.403 +            SDL_keynames[i] = "right ctrl";
   1.404 +            break;
   1.405 +        case SDLK_LCTRL:
   1.406 +            SDL_keynames[i] = "left ctrl";
   1.407 +            break;
   1.408 +        case SDLK_RALT:
   1.409 +            SDL_keynames[i] = "right alt";
   1.410 +            break;
   1.411 +        case SDLK_LALT:
   1.412 +            SDL_keynames[i] = "left alt";
   1.413 +            break;
   1.414 +        case SDLK_RMETA:
   1.415 +            SDL_keynames[i] = "right meta";
   1.416 +            break;
   1.417 +        case SDLK_LMETA:
   1.418 +            SDL_keynames[i] = "left meta";
   1.419 +            break;
   1.420 +        case SDLK_LSUPER:
   1.421 +            SDL_keynames[i] = "left super";     /* "Windows" keys */
   1.422 +            break;
   1.423 +        case SDLK_RSUPER:
   1.424 +            SDL_keynames[i] = "right super";
   1.425 +            break;
   1.426 +        case SDLK_MODE:
   1.427 +            SDL_keynames[i] = "alt gr";
   1.428 +            break;
   1.429 +        case SDLK_COMPOSE:
   1.430 +            SDL_keynames[i] = "compose";
   1.431 +            break;
   1.432  
   1.433 -	keynames[SDLK_UP] = "up";
   1.434 -	keynames[SDLK_DOWN] = "down";
   1.435 -	keynames[SDLK_RIGHT] = "right";
   1.436 -	keynames[SDLK_LEFT] = "left";
   1.437 -	keynames[SDLK_DOWN] = "down";
   1.438 -	keynames[SDLK_INSERT] = "insert";
   1.439 -	keynames[SDLK_HOME] = "home";
   1.440 -	keynames[SDLK_END] = "end";
   1.441 -	keynames[SDLK_PAGEUP] = "page up";
   1.442 -	keynames[SDLK_PAGEDOWN] = "page down";
   1.443 +        case SDLK_HELP:
   1.444 +            SDL_keynames[i] = "help";
   1.445 +            break;
   1.446 +        case SDLK_PRINT:
   1.447 +            SDL_keynames[i] = "print screen";
   1.448 +            break;
   1.449 +        case SDLK_SYSREQ:
   1.450 +            SDL_keynames[i] = "sys req";
   1.451 +            break;
   1.452 +        case SDLK_BREAK:
   1.453 +            SDL_keynames[i] = "break";
   1.454 +            break;
   1.455 +        case SDLK_MENU:
   1.456 +            SDL_keynames[i] = "menu";
   1.457 +            break;
   1.458 +        case SDLK_POWER:
   1.459 +            SDL_keynames[i] = "power";
   1.460 +            break;
   1.461 +        case SDLK_EURO:
   1.462 +            SDL_keynames[i] = "euro";
   1.463 +            break;
   1.464 +        case SDLK_UNDO:
   1.465 +            SDL_keynames[i] = "undo";
   1.466 +            break;
   1.467  
   1.468 -	keynames[SDLK_F1] = "f1";
   1.469 -	keynames[SDLK_F2] = "f2";
   1.470 -	keynames[SDLK_F3] = "f3";
   1.471 -	keynames[SDLK_F4] = "f4";
   1.472 -	keynames[SDLK_F5] = "f5";
   1.473 -	keynames[SDLK_F6] = "f6";
   1.474 -	keynames[SDLK_F7] = "f7";
   1.475 -	keynames[SDLK_F8] = "f8";
   1.476 -	keynames[SDLK_F9] = "f9";
   1.477 -	keynames[SDLK_F10] = "f10";
   1.478 -	keynames[SDLK_F11] = "f11";
   1.479 -	keynames[SDLK_F12] = "f12";
   1.480 -	keynames[SDLK_F13] = "f13";
   1.481 -	keynames[SDLK_F14] = "f14";
   1.482 -	keynames[SDLK_F15] = "f15";
   1.483 +        default:
   1.484 +            SDL_keynames[i] = NULL;
   1.485 +            break;
   1.486 +        }
   1.487 +    }
   1.488  
   1.489 -	keynames[SDLK_NUMLOCK] = "numlock";
   1.490 -	keynames[SDLK_CAPSLOCK] = "caps lock";
   1.491 -	keynames[SDLK_SCROLLOCK] = "scroll lock";
   1.492 -	keynames[SDLK_RSHIFT] = "right shift";
   1.493 -	keynames[SDLK_LSHIFT] = "left shift";
   1.494 -	keynames[SDLK_RCTRL] = "right ctrl";
   1.495 -	keynames[SDLK_LCTRL] = "left ctrl";
   1.496 -	keynames[SDLK_RALT] = "right alt";
   1.497 -	keynames[SDLK_LALT] = "left alt";
   1.498 -	keynames[SDLK_RMETA] = "right meta";
   1.499 -	keynames[SDLK_LMETA] = "left meta";
   1.500 -	keynames[SDLK_LSUPER] = "left super";	/* "Windows" keys */
   1.501 -	keynames[SDLK_RSUPER] = "right super";	
   1.502 -	keynames[SDLK_MODE] = "alt gr";
   1.503 -	keynames[SDLK_COMPOSE] = "compose";
   1.504 -
   1.505 -	keynames[SDLK_HELP] = "help";
   1.506 -	keynames[SDLK_PRINT] = "print screen";
   1.507 -	keynames[SDLK_SYSREQ] = "sys req";
   1.508 -	keynames[SDLK_BREAK] = "break";
   1.509 -	keynames[SDLK_MENU] = "menu";
   1.510 -	keynames[SDLK_POWER] = "power";
   1.511 -	keynames[SDLK_EURO] = "euro";
   1.512 -	keynames[SDLK_UNDO] = "undo";
   1.513 -
   1.514 -	/* Done.  Whew. */
   1.515 -	return(0);
   1.516 -}
   1.517 -void SDL_KeyboardQuit(void)
   1.518 -{
   1.519 +    /* Done.  Whew. */
   1.520 +    return (0);
   1.521  }
   1.522  
   1.523 -/* We lost the keyboard, so post key up messages for all pressed keys */
   1.524 -void SDL_ResetKeyboard(void)
   1.525 +SDL_Keyboard *
   1.526 +SDL_GetKeyboard(int index)
   1.527  {
   1.528 -	SDL_keysym keysym;
   1.529 -	SDLKey key;
   1.530 -
   1.531 -	SDL_memset(&keysym, 0, (sizeof keysym));
   1.532 -	for ( key=SDLK_FIRST; key<SDLK_LAST; ++key ) {
   1.533 -		if ( SDL_KeyState[key] == SDL_PRESSED ) {
   1.534 -			keysym.sym = key;
   1.535 -			SDL_PrivateKeyboard(SDL_RELEASED, &keysym);
   1.536 -		}
   1.537 -	}
   1.538 -	SDL_KeyRepeat.timestamp = 0;
   1.539 +    if (index < 0 || index >= SDL_num_keyboards) {
   1.540 +        return NULL;
   1.541 +    }
   1.542 +    return SDL_keyboards[index];
   1.543  }
   1.544  
   1.545 -int SDL_EnableUNICODE(int enable)
   1.546 +int
   1.547 +SDL_AddKeyboard(const SDL_Keyboard * keyboard, int index)
   1.548  {
   1.549 -	int old_mode;
   1.550 +    SDL_Keyboard **keyboards;
   1.551  
   1.552 -	old_mode = SDL_TranslateUNICODE;
   1.553 -	if ( enable >= 0 ) {
   1.554 -		SDL_TranslateUNICODE = enable;
   1.555 -	}
   1.556 -	return(old_mode);
   1.557 +    /* Add the keyboard to the list of keyboards */
   1.558 +    if (index < 0 || index >= SDL_num_keyboards || SDL_keyboards[index]) {
   1.559 +        keyboards =
   1.560 +            (SDL_Keyboard **) SDL_realloc(SDL_keyboards,
   1.561 +                                          (SDL_num_keyboards +
   1.562 +                                           1) * sizeof(*keyboards));
   1.563 +        if (!keyboards) {
   1.564 +            SDL_OutOfMemory();
   1.565 +            return -1;
   1.566 +        }
   1.567 +
   1.568 +        SDL_keyboards = keyboards;
   1.569 +        index = SDL_num_keyboards++;
   1.570 +    }
   1.571 +    SDL_keyboards[index] =
   1.572 +        (SDL_Keyboard *) SDL_malloc(sizeof(*SDL_keyboards[index]));
   1.573 +    if (!SDL_keyboards[index]) {
   1.574 +        SDL_OutOfMemory();
   1.575 +        return -1;
   1.576 +    }
   1.577 +    *SDL_keyboards[index] = *keyboard;
   1.578 +
   1.579 +    return index;
   1.580  }
   1.581  
   1.582 -Uint8 * SDL_GetKeyState (int *numkeys)
   1.583 +void
   1.584 +SDL_DelKeyboard(int index)
   1.585  {
   1.586 -	if ( numkeys != (int *)0 )
   1.587 -		*numkeys = SDLK_LAST;
   1.588 -	return(SDL_KeyState);
   1.589 -}
   1.590 -SDLMod SDL_GetModState (void)
   1.591 -{
   1.592 -	return(SDL_ModState);
   1.593 -}
   1.594 -void SDL_SetModState (SDLMod modstate)
   1.595 -{
   1.596 -	SDL_ModState = modstate;
   1.597 +    SDL_Keyboard *keyboard = SDL_GetKeyboard(index);
   1.598 +
   1.599 +    if (!keyboard) {
   1.600 +        return;
   1.601 +    }
   1.602 +
   1.603 +    if (keyboard->FreeKeyboard) {
   1.604 +        keyboard->FreeKeyboard(keyboard);
   1.605 +    }
   1.606 +    SDL_free(keyboard);
   1.607 +
   1.608 +    SDL_keyboards[index] = NULL;
   1.609  }
   1.610  
   1.611 -char *SDL_GetKeyName(SDLKey key)
   1.612 +void
   1.613 +SDL_ResetKeyboard(int index)
   1.614  {
   1.615 -	const char *keyname;
   1.616 +    SDL_Keyboard *keyboard = SDL_GetKeyboard(index);
   1.617 +    SDLKey key;
   1.618  
   1.619 -	keyname = NULL;
   1.620 -	if ( key < SDLK_LAST ) {
   1.621 -		keyname = keynames[key];
   1.622 -	}
   1.623 -	if ( keyname == NULL ) {
   1.624 -		keyname = "unknown key";
   1.625 -	}
   1.626 -	/* FIXME: make this function const in 1.3 */
   1.627 -	return (char *)(keyname);
   1.628 +    if (!keyboard) {
   1.629 +        return;
   1.630 +    }
   1.631 +
   1.632 +    for (key = SDLK_FIRST; key < SDLK_LAST; ++key) {
   1.633 +        if (keyboard->keystate[key] == SDL_PRESSED) {
   1.634 +            SDL_SendKeyboardKey(index, SDL_RELEASED, 0, key);
   1.635 +        }
   1.636 +    }
   1.637 +    keyboard->repeat.timestamp = 0;
   1.638  }
   1.639  
   1.640 -/* These are global for SDL_eventloop.c */
   1.641 -int SDL_PrivateKeyboard(Uint8 state, SDL_keysym *keysym)
   1.642 +void
   1.643 +SDL_KeyboardQuit(void)
   1.644  {
   1.645 -	SDL_Event event;
   1.646 -	int posted, repeatable;
   1.647 -	Uint16 modstate;
   1.648 +    int i;
   1.649  
   1.650 -	SDL_memset(&event, 0, sizeof(event));
   1.651 +    for (i = 0; i < SDL_num_keyboards; ++i) {
   1.652 +        SDL_DelKeyboard(i);
   1.653 +    }
   1.654 +    SDL_num_keyboards = 0;
   1.655 +    SDL_current_keyboard = 0;
   1.656  
   1.657 +    if (SDL_keyboards) {
   1.658 +        SDL_free(SDL_keyboards);
   1.659 +        SDL_keyboards = NULL;
   1.660 +    }
   1.661 +}
   1.662 +
   1.663 +int
   1.664 +SDL_GetNumKeyboards(void)
   1.665 +{
   1.666 +    return SDL_num_keyboards;
   1.667 +}
   1.668 +
   1.669 +int
   1.670 +SDL_SelectKeyboard(int index)
   1.671 +{
   1.672 +    if (index >= 0 && index < SDL_num_keyboards) {
   1.673 +        SDL_current_keyboard = index;
   1.674 +    }
   1.675 +    return SDL_current_keyboard;
   1.676 +}
   1.677 +
   1.678 +int
   1.679 +SDL_EnableUNICODE(int enable)
   1.680 +{
   1.681 +    int old_mode;
   1.682 +
   1.683 +    old_mode = SDL_TranslateUNICODE;
   1.684 +    if (enable >= 0) {
   1.685 +        SDL_TranslateUNICODE = enable;
   1.686 +    }
   1.687 +    return (old_mode);
   1.688 +}
   1.689 +
   1.690 +Uint8 *
   1.691 +SDL_GetKeyState(int *numkeys)
   1.692 +{
   1.693 +    SDL_Keyboard *keyboard = SDL_GetKeyboard(SDL_current_keyboard);
   1.694 +
   1.695 +    if (numkeys != (int *) 0) {
   1.696 +        *numkeys = SDLK_LAST;
   1.697 +    }
   1.698 +
   1.699 +    if (!keyboard) {
   1.700 +        return NULL;
   1.701 +    }
   1.702 +    return keyboard->keystate;
   1.703 +}
   1.704 +
   1.705 +SDLMod
   1.706 +SDL_GetModState(void)
   1.707 +{
   1.708 +    SDL_Keyboard *keyboard = SDL_GetKeyboard(SDL_current_keyboard);
   1.709 +
   1.710 +    if (!keyboard) {
   1.711 +        return KMOD_NONE;
   1.712 +    }
   1.713 +    return keyboard->modstate;
   1.714 +}
   1.715 +
   1.716 +void
   1.717 +SDL_SetModState(SDLMod modstate)
   1.718 +{
   1.719 +    SDL_Keyboard *keyboard = SDL_GetKeyboard(SDL_current_keyboard);
   1.720 +
   1.721 +    if (!keyboard) {
   1.722 +        return;
   1.723 +    }
   1.724 +    keyboard->modstate = modstate;
   1.725 +}
   1.726 +
   1.727 +const char *
   1.728 +SDL_GetKeyName(SDLKey key)
   1.729 +{
   1.730 +    const char *keyname;
   1.731 +
   1.732 +    if (key < SDL_arraysize(SDL_keynames)) {
   1.733 +        keyname = SDL_keynames[key];
   1.734 +    } else {
   1.735 +        keyname = NULL;
   1.736 +    }
   1.737 +    if (keyname == NULL) {
   1.738 +        if (key < 256) {
   1.739 +            static char temp[4];
   1.740 +            char *cvt;
   1.741 +            temp[0] = (char) key;
   1.742 +            temp[1] = '\0';
   1.743 +            cvt = SDL_iconv_string("UTF-8", "LATIN1", temp, 1);
   1.744 +            SDL_strlcpy(temp, cvt, SDL_arraysize(temp));
   1.745 +            SDL_free(cvt);
   1.746 +            keyname = temp;
   1.747 +        } else {
   1.748 +            keyname = "unknown key";
   1.749 +        }
   1.750 +    }
   1.751 +    return keyname;
   1.752 +}
   1.753 +
   1.754 +void
   1.755 +SDL_SetKeyboardFocus(int index, SDL_WindowID windowID)
   1.756 +{
   1.757 +    SDL_Keyboard *keyboard = SDL_GetKeyboard(index);
   1.758 +    int i;
   1.759 +    SDL_bool focus;
   1.760 +
   1.761 +    if (!keyboard || (keyboard->focus == windowID)) {
   1.762 +        return;
   1.763 +    }
   1.764 +
   1.765 +    /* See if the current window has lost focus */
   1.766 +    if (keyboard->focus) {
   1.767 +        focus = SDL_FALSE;
   1.768 +        for (i = 0; i < SDL_num_keyboards; ++i) {
   1.769 +            SDL_Keyboard *check;
   1.770 +            if (i != index) {
   1.771 +                check = SDL_GetKeyboard(i);
   1.772 +                if (check && check->focus == keyboard->focus) {
   1.773 +                    focus = SDL_TRUE;
   1.774 +                    break;
   1.775 +                }
   1.776 +            }
   1.777 +        }
   1.778 +        if (!focus) {
   1.779 +            SDL_SendWindowEvent(keyboard->focus, SDL_WINDOWEVENT_FOCUS_LOST,
   1.780 +                                0, 0);
   1.781 +        }
   1.782 +    }
   1.783 +
   1.784 +    keyboard->focus = windowID;
   1.785 +
   1.786 +    if (keyboard->focus) {
   1.787 +        focus = SDL_FALSE;
   1.788 +        for (i = 0; i < SDL_num_keyboards; ++i) {
   1.789 +            SDL_Keyboard *check;
   1.790 +            if (i != index) {
   1.791 +                check = SDL_GetKeyboard(i);
   1.792 +                if (check && check->focus == keyboard->focus) {
   1.793 +                    focus = SDL_TRUE;
   1.794 +                    break;
   1.795 +                }
   1.796 +            }
   1.797 +        }
   1.798 +        if (!focus) {
   1.799 +            SDL_SendWindowEvent(keyboard->focus, SDL_WINDOWEVENT_FOCUS_GAINED,
   1.800 +                                0, 0);
   1.801 +        }
   1.802 +    }
   1.803 +}
   1.804 +
   1.805 +int
   1.806 +SDL_SendKeyboardKey(int index, Uint8 state, Uint8 scancode, SDLKey key)
   1.807 +{
   1.808 +    SDL_Keyboard *keyboard = SDL_GetKeyboard(index);
   1.809 +    int posted, repeatable;
   1.810 +    Uint16 modstate;
   1.811 +    Uint8 type;
   1.812 +
   1.813 +    if (!keyboard) {
   1.814 +        return 0;
   1.815 +    }
   1.816  #if 0
   1.817 -printf("The '%s' key has been %s\n", SDL_GetKeyName(keysym->sym), 
   1.818 -				state == SDL_PRESSED ? "pressed" : "released");
   1.819 +    printf("The '%s' key has been %s\n", SDL_GetKeyName(key),
   1.820 +           state == SDL_PRESSED ? "pressed" : "released");
   1.821  #endif
   1.822 -	/* Set up the keysym */
   1.823 -	modstate = (Uint16)SDL_ModState;
   1.824 +    repeatable = 0;
   1.825 +    if (state == SDL_PRESSED) {
   1.826 +        modstate = keyboard->modstate;
   1.827 +        switch (key) {
   1.828 +        case SDLK_UNKNOWN:
   1.829 +            break;
   1.830 +        case SDLK_NUMLOCK:
   1.831 +            keyboard->modstate ^= KMOD_NUM;
   1.832 +            break;
   1.833 +        case SDLK_CAPSLOCK:
   1.834 +            keyboard->modstate ^= KMOD_CAPS;
   1.835 +            break;
   1.836 +        case SDLK_LCTRL:
   1.837 +            keyboard->modstate |= KMOD_LCTRL;
   1.838 +            break;
   1.839 +        case SDLK_RCTRL:
   1.840 +            keyboard->modstate |= KMOD_RCTRL;
   1.841 +            break;
   1.842 +        case SDLK_LSHIFT:
   1.843 +            keyboard->modstate |= KMOD_LSHIFT;
   1.844 +            break;
   1.845 +        case SDLK_RSHIFT:
   1.846 +            keyboard->modstate |= KMOD_RSHIFT;
   1.847 +            break;
   1.848 +        case SDLK_LALT:
   1.849 +            keyboard->modstate |= KMOD_LALT;
   1.850 +            break;
   1.851 +        case SDLK_RALT:
   1.852 +            keyboard->modstate |= KMOD_RALT;
   1.853 +            break;
   1.854 +        case SDLK_LMETA:
   1.855 +            keyboard->modstate |= KMOD_LMETA;
   1.856 +            break;
   1.857 +        case SDLK_RMETA:
   1.858 +            keyboard->modstate |= KMOD_RMETA;
   1.859 +            break;
   1.860 +        case SDLK_MODE:
   1.861 +            keyboard->modstate |= KMOD_MODE;
   1.862 +            break;
   1.863 +        default:
   1.864 +            repeatable = 1;
   1.865 +            break;
   1.866 +        }
   1.867 +    } else {
   1.868 +        switch (key) {
   1.869 +        case SDLK_UNKNOWN:
   1.870 +            break;
   1.871 +        case SDLK_NUMLOCK:
   1.872 +        case SDLK_CAPSLOCK:
   1.873 +            break;
   1.874 +        case SDLK_LCTRL:
   1.875 +            keyboard->modstate &= ~KMOD_LCTRL;
   1.876 +            break;
   1.877 +        case SDLK_RCTRL:
   1.878 +            keyboard->modstate &= ~KMOD_RCTRL;
   1.879 +            break;
   1.880 +        case SDLK_LSHIFT:
   1.881 +            keyboard->modstate &= ~KMOD_LSHIFT;
   1.882 +            break;
   1.883 +        case SDLK_RSHIFT:
   1.884 +            keyboard->modstate &= ~KMOD_RSHIFT;
   1.885 +            break;
   1.886 +        case SDLK_LALT:
   1.887 +            keyboard->modstate &= ~KMOD_LALT;
   1.888 +            break;
   1.889 +        case SDLK_RALT:
   1.890 +            keyboard->modstate &= ~KMOD_RALT;
   1.891 +            break;
   1.892 +        case SDLK_LMETA:
   1.893 +            keyboard->modstate &= ~KMOD_LMETA;
   1.894 +            break;
   1.895 +        case SDLK_RMETA:
   1.896 +            keyboard->modstate &= ~KMOD_RMETA;
   1.897 +            break;
   1.898 +        case SDLK_MODE:
   1.899 +            keyboard->modstate &= ~KMOD_MODE;
   1.900 +            break;
   1.901 +        default:
   1.902 +            break;
   1.903 +        }
   1.904 +        modstate = keyboard->modstate;
   1.905 +    }
   1.906  
   1.907 -	repeatable = 0;
   1.908 +    /* Figure out what type of event this is */
   1.909 +    switch (state) {
   1.910 +    case SDL_PRESSED:
   1.911 +        type = SDL_KEYDOWN;
   1.912 +        break;
   1.913 +    case SDL_RELEASED:
   1.914 +        type = SDL_KEYUP;
   1.915 +        /*
   1.916 +         * jk 991215 - Added
   1.917 +         */
   1.918 +        if (keyboard->repeat.timestamp &&
   1.919 +            keyboard->repeat.evt.key.keysym.sym == key) {
   1.920 +            keyboard->repeat.timestamp = 0;
   1.921 +        }
   1.922 +        break;
   1.923 +    default:
   1.924 +        /* Invalid state -- bail */
   1.925 +        return 0;
   1.926 +    }
   1.927  
   1.928 -	if ( state == SDL_PRESSED ) {
   1.929 -		keysym->mod = (SDLMod)modstate;
   1.930 -		switch (keysym->sym) {
   1.931 -			case SDLK_UNKNOWN:
   1.932 -				break;
   1.933 -			case SDLK_NUMLOCK:
   1.934 -				modstate ^= KMOD_NUM;
   1.935 -				if ( ! (modstate&KMOD_NUM) )
   1.936 -					state = SDL_RELEASED;
   1.937 -				keysym->mod = (SDLMod)modstate;
   1.938 -				break;
   1.939 -			case SDLK_CAPSLOCK:
   1.940 -				modstate ^= KMOD_CAPS;
   1.941 -				if ( ! (modstate&KMOD_CAPS) )
   1.942 -					state = SDL_RELEASED;
   1.943 -				keysym->mod = (SDLMod)modstate;
   1.944 -				break;
   1.945 -			case SDLK_LCTRL:
   1.946 -				modstate |= KMOD_LCTRL;
   1.947 -				break;
   1.948 -			case SDLK_RCTRL:
   1.949 -				modstate |= KMOD_RCTRL;
   1.950 -				break;
   1.951 -			case SDLK_LSHIFT:
   1.952 -				modstate |= KMOD_LSHIFT;
   1.953 -				break;
   1.954 -			case SDLK_RSHIFT:
   1.955 -				modstate |= KMOD_RSHIFT;
   1.956 -				break;
   1.957 -			case SDLK_LALT:
   1.958 -				modstate |= KMOD_LALT;
   1.959 -				break;
   1.960 -			case SDLK_RALT:
   1.961 -				modstate |= KMOD_RALT;
   1.962 -				break;
   1.963 -			case SDLK_LMETA:
   1.964 -				modstate |= KMOD_LMETA;
   1.965 -				break;
   1.966 -			case SDLK_RMETA:
   1.967 -				modstate |= KMOD_RMETA;
   1.968 -				break;
   1.969 -			case SDLK_MODE:
   1.970 -				modstate |= KMOD_MODE;
   1.971 -				break;
   1.972 -			default:
   1.973 -				repeatable = 1;
   1.974 -				break;
   1.975 -		}
   1.976 -	} else {
   1.977 -		switch (keysym->sym) {
   1.978 -			case SDLK_UNKNOWN:
   1.979 -				break;
   1.980 -			case SDLK_NUMLOCK:
   1.981 -			case SDLK_CAPSLOCK:
   1.982 -				/* Only send keydown events */
   1.983 -				return(0);
   1.984 -			case SDLK_LCTRL:
   1.985 -				modstate &= ~KMOD_LCTRL;
   1.986 -				break;
   1.987 -			case SDLK_RCTRL:
   1.988 -				modstate &= ~KMOD_RCTRL;
   1.989 -				break;
   1.990 -			case SDLK_LSHIFT:
   1.991 -				modstate &= ~KMOD_LSHIFT;
   1.992 -				break;
   1.993 -			case SDLK_RSHIFT:
   1.994 -				modstate &= ~KMOD_RSHIFT;
   1.995 -				break;
   1.996 -			case SDLK_LALT:
   1.997 -				modstate &= ~KMOD_LALT;
   1.998 -				break;
   1.999 -			case SDLK_RALT:
  1.1000 -				modstate &= ~KMOD_RALT;
  1.1001 -				break;
  1.1002 -			case SDLK_LMETA:
  1.1003 -				modstate &= ~KMOD_LMETA;
  1.1004 -				break;
  1.1005 -			case SDLK_RMETA:
  1.1006 -				modstate &= ~KMOD_RMETA;
  1.1007 -				break;
  1.1008 -			case SDLK_MODE:
  1.1009 -				modstate &= ~KMOD_MODE;
  1.1010 -				break;
  1.1011 -			default:
  1.1012 -				break;
  1.1013 -		}
  1.1014 -		keysym->mod = (SDLMod)modstate;
  1.1015 -	}
  1.1016 +    if (key != SDLK_UNKNOWN) {
  1.1017 +        /* Drop events that don't change state */
  1.1018 +        if (keyboard->keystate[key] == state) {
  1.1019 +#if 0
  1.1020 +            printf("Keyboard event didn't change state - dropped!\n");
  1.1021 +#endif
  1.1022 +            return 0;
  1.1023 +        }
  1.1024  
  1.1025 -	/* Figure out what type of event this is */
  1.1026 -	switch (state) {
  1.1027 -		case SDL_PRESSED:
  1.1028 -			event.type = SDL_KEYDOWN;
  1.1029 -			break;
  1.1030 -		case SDL_RELEASED:
  1.1031 -			event.type = SDL_KEYUP;
  1.1032 -			/*
  1.1033 -			 * jk 991215 - Added
  1.1034 -			 */
  1.1035 -			if ( SDL_KeyRepeat.timestamp &&
  1.1036 -			     SDL_KeyRepeat.evt.key.keysym.sym == keysym->sym ) {
  1.1037 -				SDL_KeyRepeat.timestamp = 0;
  1.1038 -			}
  1.1039 -			break;
  1.1040 -		default:
  1.1041 -			/* Invalid state -- bail */
  1.1042 -			return(0);
  1.1043 -	}
  1.1044 +        /* Update internal keyboard state */
  1.1045 +        keyboard->keystate[key] = state;
  1.1046 +    }
  1.1047  
  1.1048 -	if ( keysym->sym != SDLK_UNKNOWN ) {
  1.1049 -		/* Drop events that don't change state */
  1.1050 -		if ( SDL_KeyState[keysym->sym] == state ) {
  1.1051 -#if 0
  1.1052 -printf("Keyboard event didn't change state - dropped!\n");
  1.1053 -#endif
  1.1054 -			return(0);
  1.1055 -		}
  1.1056 +    /* Post the event, if desired */
  1.1057 +    posted = 0;
  1.1058 +    if (SDL_ProcessEvents[type] == SDL_ENABLE) {
  1.1059 +        SDL_Event event;
  1.1060 +        event.key.type = type;
  1.1061 +        event.key.which = (Uint8) index;
  1.1062 +        event.key.state = state;
  1.1063 +        event.key.keysym.scancode = scancode;
  1.1064 +        event.key.keysym.sym = (Uint16) key;
  1.1065 +        event.key.keysym.mod = modstate;
  1.1066 +        event.key.keysym.unicode = 0;
  1.1067 +        event.key.windowID = keyboard->focus;
  1.1068 +        /*
  1.1069 +         * jk 991215 - Added
  1.1070 +         */
  1.1071 +        if (repeatable && (keyboard->repeat.delay != 0)) {
  1.1072 +            Uint32 timestamp = SDL_GetTicks();
  1.1073 +            if (!timestamp) {
  1.1074 +                timestamp = 1;
  1.1075 +            }
  1.1076 +            keyboard->repeat.evt = event;
  1.1077 +            keyboard->repeat.firsttime = 1;
  1.1078 +            keyboard->repeat.timestamp = 1;
  1.1079 +        }
  1.1080 +        posted = (SDL_PushEvent(&event) > 0);
  1.1081 +    }
  1.1082 +    return (posted);
  1.1083 +}
  1.1084  
  1.1085 -		/* Update internal keyboard state */
  1.1086 -		SDL_ModState = (SDLMod)modstate;
  1.1087 -		SDL_KeyState[keysym->sym] = state;
  1.1088 -	}
  1.1089 +int
  1.1090 +SDL_SendKeyboardText(int index, const char *text)
  1.1091 +{
  1.1092 +    SDL_Keyboard *keyboard = SDL_GetKeyboard(index);
  1.1093 +    int posted;
  1.1094  
  1.1095 -	/* Post the event, if desired */
  1.1096 -	posted = 0;
  1.1097 -	if ( SDL_ProcessEvents[event.type] == SDL_ENABLE ) {
  1.1098 -		event.key.state = state;
  1.1099 -		event.key.keysym = *keysym;
  1.1100 -		/*
  1.1101 -		 * jk 991215 - Added
  1.1102 -		 */
  1.1103 -		if (repeatable && (SDL_KeyRepeat.delay != 0)) {
  1.1104 -			SDL_KeyRepeat.evt = event;
  1.1105 -			SDL_KeyRepeat.firsttime = 1;
  1.1106 -			SDL_KeyRepeat.timestamp=SDL_GetTicks();
  1.1107 -		}
  1.1108 -		if ( (SDL_EventOK == NULL) || SDL_EventOK(&event) ) {
  1.1109 -			posted = 1;
  1.1110 -			SDL_PushEvent(&event);
  1.1111 -		}
  1.1112 -	}
  1.1113 -	return(posted);
  1.1114 +    if (!keyboard) {
  1.1115 +        return 0;
  1.1116 +    }
  1.1117 +
  1.1118 +    /* Post the event, if desired */
  1.1119 +    posted = 0;
  1.1120 +    if (SDL_ProcessEvents[SDL_TEXTINPUT] == SDL_ENABLE) {
  1.1121 +        SDL_Event event;
  1.1122 +        event.text.type = SDL_TEXTINPUT;
  1.1123 +        event.text.which = (Uint8) index;
  1.1124 +        SDL_strlcpy(event.text.text, text, SDL_arraysize(event.text.text));
  1.1125 +        event.key.windowID = keyboard->focus;
  1.1126 +        posted = (SDL_PushEvent(&event) > 0);
  1.1127 +    }
  1.1128 +    return (posted);
  1.1129  }
  1.1130  
  1.1131  /*
  1.1132   * jk 991215 - Added
  1.1133   */
  1.1134 -void SDL_CheckKeyRepeat(void)
  1.1135 +void
  1.1136 +SDL_CheckKeyRepeat(void)
  1.1137  {
  1.1138 -	if ( SDL_KeyRepeat.timestamp ) {
  1.1139 -		Uint32 now, interval;
  1.1140 +    int i;
  1.1141  
  1.1142 -		now = SDL_GetTicks();
  1.1143 -		interval = (now - SDL_KeyRepeat.timestamp);
  1.1144 -		if ( SDL_KeyRepeat.firsttime ) {
  1.1145 -			if ( interval > (Uint32)SDL_KeyRepeat.delay ) {
  1.1146 -				SDL_KeyRepeat.timestamp = now;
  1.1147 -				SDL_KeyRepeat.firsttime = 0;
  1.1148 -			}
  1.1149 -		} else {
  1.1150 -			if ( interval > (Uint32)SDL_KeyRepeat.interval ) {
  1.1151 -				SDL_KeyRepeat.timestamp = now;
  1.1152 -				if ( (SDL_EventOK == NULL) || SDL_EventOK(&SDL_KeyRepeat.evt) ) {
  1.1153 -					SDL_PushEvent(&SDL_KeyRepeat.evt);
  1.1154 -				}
  1.1155 -			}
  1.1156 -		}
  1.1157 -	}
  1.1158 +    for (i = 0; i < SDL_num_keyboards; ++i) {
  1.1159 +        SDL_Keyboard *keyboard = SDL_keyboards[i];
  1.1160 +
  1.1161 +        if (!keyboard) {
  1.1162 +            continue;
  1.1163 +        }
  1.1164 +
  1.1165 +        if (keyboard->repeat.timestamp) {
  1.1166 +            Uint32 now, interval;
  1.1167 +
  1.1168 +            now = SDL_GetTicks();
  1.1169 +            interval = (now - keyboard->repeat.timestamp);
  1.1170 +            if (keyboard->repeat.firsttime) {
  1.1171 +                if (interval > (Uint32) keyboard->repeat.delay) {
  1.1172 +                    keyboard->repeat.timestamp = now;
  1.1173 +                    keyboard->repeat.firsttime = 0;
  1.1174 +                }
  1.1175 +            } else {
  1.1176 +                if (interval > (Uint32) keyboard->repeat.interval) {
  1.1177 +                    keyboard->repeat.timestamp = now;
  1.1178 +                    SDL_PushEvent(&keyboard->repeat.evt);
  1.1179 +                }
  1.1180 +            }
  1.1181 +        }
  1.1182 +    }
  1.1183  }
  1.1184  
  1.1185 -int SDL_EnableKeyRepeat(int delay, int interval)
  1.1186 +int
  1.1187 +SDL_EnableKeyRepeat(int delay, int interval)
  1.1188  {
  1.1189 -	if ( (delay < 0) || (interval < 0) ) {
  1.1190 -		SDL_SetError("keyboard repeat value less than zero");
  1.1191 -		return(-1);
  1.1192 -	}
  1.1193 -	SDL_KeyRepeat.firsttime = 0;
  1.1194 -	SDL_KeyRepeat.delay = delay;
  1.1195 -	SDL_KeyRepeat.interval = interval;
  1.1196 -	SDL_KeyRepeat.timestamp = 0;
  1.1197 -	return(0);
  1.1198 +    SDL_Keyboard *keyboard = SDL_GetKeyboard(SDL_current_keyboard);
  1.1199 +
  1.1200 +    if (!keyboard) {
  1.1201 +        SDL_SetError("No keyboard is currently selected");
  1.1202 +        return -1;
  1.1203 +    }
  1.1204 +
  1.1205 +    if ((delay < 0) || (interval < 0)) {
  1.1206 +        SDL_SetError("keyboard repeat value less than zero");
  1.1207 +        return -1;
  1.1208 +    }
  1.1209 +
  1.1210 +    keyboard->repeat.firsttime = 0;
  1.1211 +    keyboard->repeat.delay = delay;
  1.1212 +    keyboard->repeat.interval = interval;
  1.1213 +    keyboard->repeat.timestamp = 0;
  1.1214 +
  1.1215 +    return 0;
  1.1216  }
  1.1217  
  1.1218 -void SDL_GetKeyRepeat(int *delay, int *interval)
  1.1219 +void
  1.1220 +SDL_GetKeyRepeat(int *delay, int *interval)
  1.1221  {
  1.1222 -	*delay = SDL_KeyRepeat.delay;
  1.1223 -	*interval = SDL_KeyRepeat.interval;
  1.1224 +    SDL_Keyboard *keyboard = SDL_GetKeyboard(SDL_current_keyboard);
  1.1225 +
  1.1226 +    if (!keyboard) {
  1.1227 +        if (delay) {
  1.1228 +            *delay = 0;
  1.1229 +        }
  1.1230 +        if (interval) {
  1.1231 +            *interval = 0;
  1.1232 +        }
  1.1233 +        return;
  1.1234 +    }
  1.1235 +    if (delay) {
  1.1236 +        *delay = keyboard->repeat.delay;
  1.1237 +    }
  1.1238 +    if (interval) {
  1.1239 +        *interval = keyboard->repeat.interval;
  1.1240 +    }
  1.1241  }
  1.1242  
  1.1243 +/* vi: set ts=4 sw=4 expandtab: */