src/events/SDL_keyboard.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 28 May 2006 13:04:16 +0000
branchSDL-1.3
changeset 1662 782fd950bd46
parent 1659 14717b52abc0
child 1668 4da1ee79c9af
permissions -rw-r--r--
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.

WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid.

The code is now run through a consistent indent format:
indent -i4 -nut -nsc -br -ce

The headers are being converted to automatically generate doxygen documentation.
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2006 Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Lesser General Public
     7     License as published by the Free Software Foundation; either
     8     version 2.1 of the License, or (at your option) any later version.
     9 
    10     This library is distributed in the hope that it will be useful,
    11     but WITHOUT ANY WARRANTY; without even the implied warranty of
    12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13     Lesser General Public License for more details.
    14 
    15     You should have received a copy of the GNU Lesser General Public
    16     License along with this library; if not, write to the Free Software
    17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 #include "SDL_config.h"
    23 
    24 /* General keyboard handling code for SDL */
    25 
    26 #include "SDL_timer.h"
    27 #include "SDL_events.h"
    28 #include "SDL_events_c.h"
    29 #include "SDL_sysevents.h"
    30 
    31 
    32 /* Global keystate information */
    33 static Uint8 SDL_KeyState[SDLK_LAST];
    34 static SDLMod SDL_ModState;
    35 int SDL_TranslateUNICODE = 0;
    36 
    37 static const char *keynames[SDLK_LAST]; /* Array of keycode names */
    38 
    39 /*
    40  * jk 991215 - added
    41  */
    42 struct
    43 {
    44     int firsttime;              /* if we check against the delay or repeat value */
    45     int delay;                  /* the delay before we start repeating */
    46     int interval;               /* the delay between key repeat events */
    47     Uint32 timestamp;           /* the time the first keydown event occurred */
    48 
    49     SDL_Event evt;              /* the event we are supposed to repeat */
    50 } SDL_KeyRepeat;
    51 
    52 /* Public functions */
    53 int
    54 SDL_KeyboardInit (void)
    55 {
    56     SDL_VideoDevice *_this = SDL_GetVideoDevice ();
    57 
    58     /* Set default mode of UNICODE translation */
    59     SDL_EnableUNICODE (DEFAULT_UNICODE_TRANSLATION);
    60 
    61     /* Initialize the tables */
    62     SDL_ModState = KMOD_NONE;
    63     SDL_memset ((void *) keynames, 0, sizeof (keynames));
    64     SDL_memset (SDL_KeyState, 0, sizeof (SDL_KeyState));
    65     _this->InitOSKeymap (_this);
    66 
    67     SDL_EnableKeyRepeat (0, 0);
    68 
    69     /* Fill in the blanks in keynames */
    70     keynames[SDLK_BACKSPACE] = "backspace";
    71     keynames[SDLK_TAB] = "tab";
    72     keynames[SDLK_CLEAR] = "clear";
    73     keynames[SDLK_RETURN] = "return";
    74     keynames[SDLK_PAUSE] = "pause";
    75     keynames[SDLK_ESCAPE] = "escape";
    76     keynames[SDLK_SPACE] = "space";
    77     keynames[SDLK_EXCLAIM] = "!";
    78     keynames[SDLK_QUOTEDBL] = "\"";
    79     keynames[SDLK_HASH] = "#";
    80     keynames[SDLK_DOLLAR] = "$";
    81     keynames[SDLK_AMPERSAND] = "&";
    82     keynames[SDLK_QUOTE] = "'";
    83     keynames[SDLK_LEFTPAREN] = "(";
    84     keynames[SDLK_RIGHTPAREN] = ")";
    85     keynames[SDLK_ASTERISK] = "*";
    86     keynames[SDLK_PLUS] = "+";
    87     keynames[SDLK_COMMA] = ",";
    88     keynames[SDLK_MINUS] = "-";
    89     keynames[SDLK_PERIOD] = ".";
    90     keynames[SDLK_SLASH] = "/";
    91     keynames[SDLK_0] = "0";
    92     keynames[SDLK_1] = "1";
    93     keynames[SDLK_2] = "2";
    94     keynames[SDLK_3] = "3";
    95     keynames[SDLK_4] = "4";
    96     keynames[SDLK_5] = "5";
    97     keynames[SDLK_6] = "6";
    98     keynames[SDLK_7] = "7";
    99     keynames[SDLK_8] = "8";
   100     keynames[SDLK_9] = "9";
   101     keynames[SDLK_COLON] = ":";
   102     keynames[SDLK_SEMICOLON] = ";";
   103     keynames[SDLK_LESS] = "<";
   104     keynames[SDLK_EQUALS] = "=";
   105     keynames[SDLK_GREATER] = ">";
   106     keynames[SDLK_QUESTION] = "?";
   107     keynames[SDLK_AT] = "@";
   108     keynames[SDLK_LEFTBRACKET] = "[";
   109     keynames[SDLK_BACKSLASH] = "\\";
   110     keynames[SDLK_RIGHTBRACKET] = "]";
   111     keynames[SDLK_CARET] = "^";
   112     keynames[SDLK_UNDERSCORE] = "_";
   113     keynames[SDLK_BACKQUOTE] = "`";
   114     keynames[SDLK_a] = "a";
   115     keynames[SDLK_b] = "b";
   116     keynames[SDLK_c] = "c";
   117     keynames[SDLK_d] = "d";
   118     keynames[SDLK_e] = "e";
   119     keynames[SDLK_f] = "f";
   120     keynames[SDLK_g] = "g";
   121     keynames[SDLK_h] = "h";
   122     keynames[SDLK_i] = "i";
   123     keynames[SDLK_j] = "j";
   124     keynames[SDLK_k] = "k";
   125     keynames[SDLK_l] = "l";
   126     keynames[SDLK_m] = "m";
   127     keynames[SDLK_n] = "n";
   128     keynames[SDLK_o] = "o";
   129     keynames[SDLK_p] = "p";
   130     keynames[SDLK_q] = "q";
   131     keynames[SDLK_r] = "r";
   132     keynames[SDLK_s] = "s";
   133     keynames[SDLK_t] = "t";
   134     keynames[SDLK_u] = "u";
   135     keynames[SDLK_v] = "v";
   136     keynames[SDLK_w] = "w";
   137     keynames[SDLK_x] = "x";
   138     keynames[SDLK_y] = "y";
   139     keynames[SDLK_z] = "z";
   140     keynames[SDLK_DELETE] = "delete";
   141 
   142     keynames[SDLK_WORLD_0] = "world 0";
   143     keynames[SDLK_WORLD_1] = "world 1";
   144     keynames[SDLK_WORLD_2] = "world 2";
   145     keynames[SDLK_WORLD_3] = "world 3";
   146     keynames[SDLK_WORLD_4] = "world 4";
   147     keynames[SDLK_WORLD_5] = "world 5";
   148     keynames[SDLK_WORLD_6] = "world 6";
   149     keynames[SDLK_WORLD_7] = "world 7";
   150     keynames[SDLK_WORLD_8] = "world 8";
   151     keynames[SDLK_WORLD_9] = "world 9";
   152     keynames[SDLK_WORLD_10] = "world 10";
   153     keynames[SDLK_WORLD_11] = "world 11";
   154     keynames[SDLK_WORLD_12] = "world 12";
   155     keynames[SDLK_WORLD_13] = "world 13";
   156     keynames[SDLK_WORLD_14] = "world 14";
   157     keynames[SDLK_WORLD_15] = "world 15";
   158     keynames[SDLK_WORLD_16] = "world 16";
   159     keynames[SDLK_WORLD_17] = "world 17";
   160     keynames[SDLK_WORLD_18] = "world 18";
   161     keynames[SDLK_WORLD_19] = "world 19";
   162     keynames[SDLK_WORLD_20] = "world 20";
   163     keynames[SDLK_WORLD_21] = "world 21";
   164     keynames[SDLK_WORLD_22] = "world 22";
   165     keynames[SDLK_WORLD_23] = "world 23";
   166     keynames[SDLK_WORLD_24] = "world 24";
   167     keynames[SDLK_WORLD_25] = "world 25";
   168     keynames[SDLK_WORLD_26] = "world 26";
   169     keynames[SDLK_WORLD_27] = "world 27";
   170     keynames[SDLK_WORLD_28] = "world 28";
   171     keynames[SDLK_WORLD_29] = "world 29";
   172     keynames[SDLK_WORLD_30] = "world 30";
   173     keynames[SDLK_WORLD_31] = "world 31";
   174     keynames[SDLK_WORLD_32] = "world 32";
   175     keynames[SDLK_WORLD_33] = "world 33";
   176     keynames[SDLK_WORLD_34] = "world 34";
   177     keynames[SDLK_WORLD_35] = "world 35";
   178     keynames[SDLK_WORLD_36] = "world 36";
   179     keynames[SDLK_WORLD_37] = "world 37";
   180     keynames[SDLK_WORLD_38] = "world 38";
   181     keynames[SDLK_WORLD_39] = "world 39";
   182     keynames[SDLK_WORLD_40] = "world 40";
   183     keynames[SDLK_WORLD_41] = "world 41";
   184     keynames[SDLK_WORLD_42] = "world 42";
   185     keynames[SDLK_WORLD_43] = "world 43";
   186     keynames[SDLK_WORLD_44] = "world 44";
   187     keynames[SDLK_WORLD_45] = "world 45";
   188     keynames[SDLK_WORLD_46] = "world 46";
   189     keynames[SDLK_WORLD_47] = "world 47";
   190     keynames[SDLK_WORLD_48] = "world 48";
   191     keynames[SDLK_WORLD_49] = "world 49";
   192     keynames[SDLK_WORLD_50] = "world 50";
   193     keynames[SDLK_WORLD_51] = "world 51";
   194     keynames[SDLK_WORLD_52] = "world 52";
   195     keynames[SDLK_WORLD_53] = "world 53";
   196     keynames[SDLK_WORLD_54] = "world 54";
   197     keynames[SDLK_WORLD_55] = "world 55";
   198     keynames[SDLK_WORLD_56] = "world 56";
   199     keynames[SDLK_WORLD_57] = "world 57";
   200     keynames[SDLK_WORLD_58] = "world 58";
   201     keynames[SDLK_WORLD_59] = "world 59";
   202     keynames[SDLK_WORLD_60] = "world 60";
   203     keynames[SDLK_WORLD_61] = "world 61";
   204     keynames[SDLK_WORLD_62] = "world 62";
   205     keynames[SDLK_WORLD_63] = "world 63";
   206     keynames[SDLK_WORLD_64] = "world 64";
   207     keynames[SDLK_WORLD_65] = "world 65";
   208     keynames[SDLK_WORLD_66] = "world 66";
   209     keynames[SDLK_WORLD_67] = "world 67";
   210     keynames[SDLK_WORLD_68] = "world 68";
   211     keynames[SDLK_WORLD_69] = "world 69";
   212     keynames[SDLK_WORLD_70] = "world 70";
   213     keynames[SDLK_WORLD_71] = "world 71";
   214     keynames[SDLK_WORLD_72] = "world 72";
   215     keynames[SDLK_WORLD_73] = "world 73";
   216     keynames[SDLK_WORLD_74] = "world 74";
   217     keynames[SDLK_WORLD_75] = "world 75";
   218     keynames[SDLK_WORLD_76] = "world 76";
   219     keynames[SDLK_WORLD_77] = "world 77";
   220     keynames[SDLK_WORLD_78] = "world 78";
   221     keynames[SDLK_WORLD_79] = "world 79";
   222     keynames[SDLK_WORLD_80] = "world 80";
   223     keynames[SDLK_WORLD_81] = "world 81";
   224     keynames[SDLK_WORLD_82] = "world 82";
   225     keynames[SDLK_WORLD_83] = "world 83";
   226     keynames[SDLK_WORLD_84] = "world 84";
   227     keynames[SDLK_WORLD_85] = "world 85";
   228     keynames[SDLK_WORLD_86] = "world 86";
   229     keynames[SDLK_WORLD_87] = "world 87";
   230     keynames[SDLK_WORLD_88] = "world 88";
   231     keynames[SDLK_WORLD_89] = "world 89";
   232     keynames[SDLK_WORLD_90] = "world 90";
   233     keynames[SDLK_WORLD_91] = "world 91";
   234     keynames[SDLK_WORLD_92] = "world 92";
   235     keynames[SDLK_WORLD_93] = "world 93";
   236     keynames[SDLK_WORLD_94] = "world 94";
   237     keynames[SDLK_WORLD_95] = "world 95";
   238 
   239     keynames[SDLK_KP0] = "[0]";
   240     keynames[SDLK_KP1] = "[1]";
   241     keynames[SDLK_KP2] = "[2]";
   242     keynames[SDLK_KP3] = "[3]";
   243     keynames[SDLK_KP4] = "[4]";
   244     keynames[SDLK_KP5] = "[5]";
   245     keynames[SDLK_KP6] = "[6]";
   246     keynames[SDLK_KP7] = "[7]";
   247     keynames[SDLK_KP8] = "[8]";
   248     keynames[SDLK_KP9] = "[9]";
   249     keynames[SDLK_KP_PERIOD] = "[.]";
   250     keynames[SDLK_KP_DIVIDE] = "[/]";
   251     keynames[SDLK_KP_MULTIPLY] = "[*]";
   252     keynames[SDLK_KP_MINUS] = "[-]";
   253     keynames[SDLK_KP_PLUS] = "[+]";
   254     keynames[SDLK_KP_ENTER] = "enter";
   255     keynames[SDLK_KP_EQUALS] = "equals";
   256 
   257     keynames[SDLK_UP] = "up";
   258     keynames[SDLK_DOWN] = "down";
   259     keynames[SDLK_RIGHT] = "right";
   260     keynames[SDLK_LEFT] = "left";
   261     keynames[SDLK_DOWN] = "down";
   262     keynames[SDLK_INSERT] = "insert";
   263     keynames[SDLK_HOME] = "home";
   264     keynames[SDLK_END] = "end";
   265     keynames[SDLK_PAGEUP] = "page up";
   266     keynames[SDLK_PAGEDOWN] = "page down";
   267 
   268     keynames[SDLK_F1] = "f1";
   269     keynames[SDLK_F2] = "f2";
   270     keynames[SDLK_F3] = "f3";
   271     keynames[SDLK_F4] = "f4";
   272     keynames[SDLK_F5] = "f5";
   273     keynames[SDLK_F6] = "f6";
   274     keynames[SDLK_F7] = "f7";
   275     keynames[SDLK_F8] = "f8";
   276     keynames[SDLK_F9] = "f9";
   277     keynames[SDLK_F10] = "f10";
   278     keynames[SDLK_F11] = "f11";
   279     keynames[SDLK_F12] = "f12";
   280     keynames[SDLK_F13] = "f13";
   281     keynames[SDLK_F14] = "f14";
   282     keynames[SDLK_F15] = "f15";
   283 
   284     keynames[SDLK_NUMLOCK] = "numlock";
   285     keynames[SDLK_CAPSLOCK] = "caps lock";
   286     keynames[SDLK_SCROLLOCK] = "scroll lock";
   287     keynames[SDLK_RSHIFT] = "right shift";
   288     keynames[SDLK_LSHIFT] = "left shift";
   289     keynames[SDLK_RCTRL] = "right ctrl";
   290     keynames[SDLK_LCTRL] = "left ctrl";
   291     keynames[SDLK_RALT] = "right alt";
   292     keynames[SDLK_LALT] = "left alt";
   293     keynames[SDLK_RMETA] = "right meta";
   294     keynames[SDLK_LMETA] = "left meta";
   295     keynames[SDLK_LSUPER] = "left super";       /* "Windows" keys */
   296     keynames[SDLK_RSUPER] = "right super";
   297     keynames[SDLK_MODE] = "alt gr";
   298     keynames[SDLK_COMPOSE] = "compose";
   299 
   300     keynames[SDLK_HELP] = "help";
   301     keynames[SDLK_PRINT] = "print screen";
   302     keynames[SDLK_SYSREQ] = "sys req";
   303     keynames[SDLK_BREAK] = "break";
   304     keynames[SDLK_MENU] = "menu";
   305     keynames[SDLK_POWER] = "power";
   306     keynames[SDLK_EURO] = "euro";
   307     keynames[SDLK_UNDO] = "undo";
   308 
   309     /* Done.  Whew. */
   310     return (0);
   311 }
   312 
   313 void
   314 SDL_KeyboardQuit (void)
   315 {
   316 }
   317 
   318 /* We lost the keyboard, so post key up messages for all pressed keys */
   319 void
   320 SDL_ResetKeyboard (void)
   321 {
   322     SDL_keysym keysym;
   323     SDLKey key;
   324 
   325     SDL_memset (&keysym, 0, (sizeof keysym));
   326     for (key = SDLK_FIRST; key < SDLK_LAST; ++key) {
   327         if (SDL_KeyState[key] == SDL_PRESSED) {
   328             keysym.sym = key;
   329             SDL_PrivateKeyboard (SDL_RELEASED, &keysym);
   330         }
   331     }
   332     SDL_KeyRepeat.timestamp = 0;
   333 }
   334 
   335 int
   336 SDL_EnableUNICODE (int enable)
   337 {
   338     int old_mode;
   339 
   340     old_mode = SDL_TranslateUNICODE;
   341     if (enable >= 0) {
   342         SDL_TranslateUNICODE = enable;
   343     }
   344     return (old_mode);
   345 }
   346 
   347 Uint8 *
   348 SDL_GetKeyState (int *numkeys)
   349 {
   350     if (numkeys != (int *) 0)
   351         *numkeys = SDLK_LAST;
   352     return (SDL_KeyState);
   353 }
   354 
   355 SDLMod
   356 SDL_GetModState (void)
   357 {
   358     return (SDL_ModState);
   359 }
   360 
   361 void
   362 SDL_SetModState (SDLMod modstate)
   363 {
   364     SDL_ModState = modstate;
   365 }
   366 
   367 char *
   368 SDL_GetKeyName (SDLKey key)
   369 {
   370     const char *keyname;
   371 
   372     keyname = NULL;
   373     if (key < SDLK_LAST) {
   374         keyname = keynames[key];
   375     }
   376     if (keyname == NULL) {
   377         keyname = "unknown key";
   378     }
   379     /* FIXME: make this function const in 1.3 */
   380     return (char *) (keyname);
   381 }
   382 
   383 /* These are global for SDL_eventloop.c */
   384 int
   385 SDL_PrivateKeyboard (Uint8 state, SDL_keysym * keysym)
   386 {
   387     SDL_Event event;
   388     int posted, repeatable;
   389     Uint16 modstate;
   390 
   391     SDL_memset (&event, 0, sizeof (event));
   392 
   393 #if 0
   394     printf ("The '%s' key has been %s\n", SDL_GetKeyName (keysym->sym),
   395             state == SDL_PRESSED ? "pressed" : "released");
   396 #endif
   397     /* Set up the keysym */
   398     modstate = (Uint16) SDL_ModState;
   399 
   400     repeatable = 0;
   401 
   402     if (state == SDL_PRESSED) {
   403         keysym->mod = (SDLMod) modstate;
   404         switch (keysym->sym) {
   405         case SDLK_UNKNOWN:
   406             break;
   407         case SDLK_NUMLOCK:
   408             modstate ^= KMOD_NUM;
   409             if (!(modstate & KMOD_NUM))
   410                 state = SDL_RELEASED;
   411             keysym->mod = (SDLMod) modstate;
   412             break;
   413         case SDLK_CAPSLOCK:
   414             modstate ^= KMOD_CAPS;
   415             if (!(modstate & KMOD_CAPS))
   416                 state = SDL_RELEASED;
   417             keysym->mod = (SDLMod) modstate;
   418             break;
   419         case SDLK_LCTRL:
   420             modstate |= KMOD_LCTRL;
   421             break;
   422         case SDLK_RCTRL:
   423             modstate |= KMOD_RCTRL;
   424             break;
   425         case SDLK_LSHIFT:
   426             modstate |= KMOD_LSHIFT;
   427             break;
   428         case SDLK_RSHIFT:
   429             modstate |= KMOD_RSHIFT;
   430             break;
   431         case SDLK_LALT:
   432             modstate |= KMOD_LALT;
   433             break;
   434         case SDLK_RALT:
   435             modstate |= KMOD_RALT;
   436             break;
   437         case SDLK_LMETA:
   438             modstate |= KMOD_LMETA;
   439             break;
   440         case SDLK_RMETA:
   441             modstate |= KMOD_RMETA;
   442             break;
   443         case SDLK_MODE:
   444             modstate |= KMOD_MODE;
   445             break;
   446         default:
   447             repeatable = 1;
   448             break;
   449         }
   450     } else {
   451         switch (keysym->sym) {
   452         case SDLK_UNKNOWN:
   453             break;
   454         case SDLK_NUMLOCK:
   455         case SDLK_CAPSLOCK:
   456             /* Only send keydown events */
   457             return (0);
   458         case SDLK_LCTRL:
   459             modstate &= ~KMOD_LCTRL;
   460             break;
   461         case SDLK_RCTRL:
   462             modstate &= ~KMOD_RCTRL;
   463             break;
   464         case SDLK_LSHIFT:
   465             modstate &= ~KMOD_LSHIFT;
   466             break;
   467         case SDLK_RSHIFT:
   468             modstate &= ~KMOD_RSHIFT;
   469             break;
   470         case SDLK_LALT:
   471             modstate &= ~KMOD_LALT;
   472             break;
   473         case SDLK_RALT:
   474             modstate &= ~KMOD_RALT;
   475             break;
   476         case SDLK_LMETA:
   477             modstate &= ~KMOD_LMETA;
   478             break;
   479         case SDLK_RMETA:
   480             modstate &= ~KMOD_RMETA;
   481             break;
   482         case SDLK_MODE:
   483             modstate &= ~KMOD_MODE;
   484             break;
   485         default:
   486             break;
   487         }
   488         keysym->mod = (SDLMod) modstate;
   489     }
   490 
   491     /* Figure out what type of event this is */
   492     switch (state) {
   493     case SDL_PRESSED:
   494         event.type = SDL_KEYDOWN;
   495         break;
   496     case SDL_RELEASED:
   497         event.type = SDL_KEYUP;
   498         /*
   499          * jk 991215 - Added
   500          */
   501         if (SDL_KeyRepeat.timestamp &&
   502             SDL_KeyRepeat.evt.key.keysym.sym == keysym->sym) {
   503             SDL_KeyRepeat.timestamp = 0;
   504         }
   505         break;
   506     default:
   507         /* Invalid state -- bail */
   508         return (0);
   509     }
   510 
   511     if (keysym->sym != SDLK_UNKNOWN) {
   512         /* Drop events that don't change state */
   513         if (SDL_KeyState[keysym->sym] == state) {
   514 #if 0
   515             printf ("Keyboard event didn't change state - dropped!\n");
   516 #endif
   517             return (0);
   518         }
   519 
   520         /* Update internal keyboard state */
   521         SDL_ModState = (SDLMod) modstate;
   522         SDL_KeyState[keysym->sym] = state;
   523     }
   524 
   525     /* Post the event, if desired */
   526     posted = 0;
   527     if (SDL_ProcessEvents[event.type] == SDL_ENABLE) {
   528         event.key.state = state;
   529         event.key.keysym = *keysym;
   530         /*
   531          * jk 991215 - Added
   532          */
   533         if (repeatable && (SDL_KeyRepeat.delay != 0)) {
   534             SDL_KeyRepeat.evt = event;
   535             SDL_KeyRepeat.firsttime = 1;
   536             SDL_KeyRepeat.timestamp = SDL_GetTicks ();
   537         }
   538         if ((SDL_EventOK == NULL) || SDL_EventOK (&event)) {
   539             posted = 1;
   540             SDL_PushEvent (&event);
   541         }
   542     }
   543     return (posted);
   544 }
   545 
   546 /*
   547  * jk 991215 - Added
   548  */
   549 void
   550 SDL_CheckKeyRepeat (void)
   551 {
   552     if (SDL_KeyRepeat.timestamp) {
   553         Uint32 now, interval;
   554 
   555         now = SDL_GetTicks ();
   556         interval = (now - SDL_KeyRepeat.timestamp);
   557         if (SDL_KeyRepeat.firsttime) {
   558             if (interval > (Uint32) SDL_KeyRepeat.delay) {
   559                 SDL_KeyRepeat.timestamp = now;
   560                 SDL_KeyRepeat.firsttime = 0;
   561             }
   562         } else {
   563             if (interval > (Uint32) SDL_KeyRepeat.interval) {
   564                 SDL_KeyRepeat.timestamp = now;
   565                 if ((SDL_EventOK == NULL)
   566                     || SDL_EventOK (&SDL_KeyRepeat.evt)) {
   567                     SDL_PushEvent (&SDL_KeyRepeat.evt);
   568                 }
   569             }
   570         }
   571     }
   572 }
   573 
   574 int
   575 SDL_EnableKeyRepeat (int delay, int interval)
   576 {
   577     if ((delay < 0) || (interval < 0)) {
   578         SDL_SetError ("keyboard repeat value less than zero");
   579         return (-1);
   580     }
   581     SDL_KeyRepeat.firsttime = 0;
   582     SDL_KeyRepeat.delay = delay;
   583     SDL_KeyRepeat.interval = interval;
   584     SDL_KeyRepeat.timestamp = 0;
   585     return (0);
   586 }
   587 
   588 void
   589 SDL_GetKeyRepeat (int *delay, int *interval)
   590 {
   591     *delay = SDL_KeyRepeat.delay;
   592     *interval = SDL_KeyRepeat.interval;
   593 }
   594 
   595 /* vi: set ts=4 sw=4 expandtab: */