src/events/SDL_keyboard.c
author Sam Lantinga <slouken@libsdl.org>
Sat, 08 Jul 2006 20:07:08 +0000
branchSDL-1.3
changeset 1731 875c3cf1a12c
parent 1724 6c63fc2bd986
child 1732 fd65f12b6de6
permissions -rw-r--r--
SDL_PushEvent() calls the event filter code, and has a return value to tell
whether or not the event was actually pushed.
SDL_GetEventFilter() now returns an SDL_bool instead of the filter function.
     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 keyboard information */
    33 int SDL_TranslateUNICODE = 0;
    34 static int SDL_num_keyboards;
    35 static int SDL_current_keyboard;
    36 static SDL_Keyboard **SDL_keyboards;
    37 
    38 static const char *SDL_keynames[SDLK_LAST];     /* Array of keycode names */
    39 
    40 /* Public functions */
    41 int
    42 SDL_KeyboardInit(void)
    43 {
    44     int i;
    45 
    46     /* Set default mode of UNICODE translation */
    47     SDL_EnableUNICODE(DEFAULT_UNICODE_TRANSLATION);
    48 
    49     /* Initialize the tables */
    50     for (i = 0; i < SDL_arraysize(SDL_keynames); ++i) {
    51         switch (i) {
    52         case SDLK_BACKSPACE:
    53             SDL_keynames[i] = "backspace";
    54             break;
    55         case SDLK_TAB:
    56             SDL_keynames[i] = "tab";
    57             break;
    58         case SDLK_CLEAR:
    59             SDL_keynames[i] = "clear";
    60             break;
    61         case SDLK_RETURN:
    62             SDL_keynames[i] = "return";
    63             break;
    64         case SDLK_PAUSE:
    65             SDL_keynames[i] = "pause";
    66             break;
    67         case SDLK_ESCAPE:
    68             SDL_keynames[i] = "escape";
    69             break;
    70         case SDLK_SPACE:
    71             SDL_keynames[i] = "space";
    72             break;
    73 
    74         case SDLK_KP0:
    75             SDL_keynames[i] = "[0]";
    76             break;
    77         case SDLK_KP1:
    78             SDL_keynames[i] = "[1]";
    79             break;
    80         case SDLK_KP2:
    81             SDL_keynames[i] = "[2]";
    82             break;
    83         case SDLK_KP3:
    84             SDL_keynames[i] = "[3]";
    85             break;
    86         case SDLK_KP4:
    87             SDL_keynames[i] = "[4]";
    88             break;
    89         case SDLK_KP5:
    90             SDL_keynames[i] = "[5]";
    91             break;
    92         case SDLK_KP6:
    93             SDL_keynames[i] = "[6]";
    94             break;
    95         case SDLK_KP7:
    96             SDL_keynames[i] = "[7]";
    97             break;
    98         case SDLK_KP8:
    99             SDL_keynames[i] = "[8]";
   100             break;
   101         case SDLK_KP9:
   102             SDL_keynames[i] = "[9]";
   103             break;
   104         case SDLK_KP_PERIOD:
   105             SDL_keynames[i] = "[.]";
   106             break;
   107         case SDLK_KP_DIVIDE:
   108             SDL_keynames[i] = "[/]";
   109             break;
   110         case SDLK_KP_MULTIPLY:
   111             SDL_keynames[i] = "[*]";
   112             break;
   113         case SDLK_KP_MINUS:
   114             SDL_keynames[i] = "[-]";
   115             break;
   116         case SDLK_KP_PLUS:
   117             SDL_keynames[i] = "[+]";
   118             break;
   119         case SDLK_KP_ENTER:
   120             SDL_keynames[i] = "enter";
   121             break;
   122         case SDLK_KP_EQUALS:
   123             SDL_keynames[i] = "equals";
   124             break;
   125 
   126         case SDLK_UP:
   127             SDL_keynames[i] = "up";
   128             break;
   129         case SDLK_DOWN:
   130             SDL_keynames[i] = "down";
   131             break;
   132         case SDLK_RIGHT:
   133             SDL_keynames[i] = "right";
   134             break;
   135         case SDLK_LEFT:
   136             SDL_keynames[i] = "left";
   137             break;
   138         case SDLK_INSERT:
   139             SDL_keynames[i] = "insert";
   140             break;
   141         case SDLK_HOME:
   142             SDL_keynames[i] = "home";
   143             break;
   144         case SDLK_END:
   145             SDL_keynames[i] = "end";
   146             break;
   147         case SDLK_PAGEUP:
   148             SDL_keynames[i] = "page up";
   149             break;
   150         case SDLK_PAGEDOWN:
   151             SDL_keynames[i] = "page down";
   152             break;
   153 
   154         case SDLK_F1:
   155             SDL_keynames[i] = "f1";
   156             break;
   157         case SDLK_F2:
   158             SDL_keynames[i] = "f2";
   159             break;
   160         case SDLK_F3:
   161             SDL_keynames[i] = "f3";
   162             break;
   163         case SDLK_F4:
   164             SDL_keynames[i] = "f4";
   165             break;
   166         case SDLK_F5:
   167             SDL_keynames[i] = "f5";
   168             break;
   169         case SDLK_F6:
   170             SDL_keynames[i] = "f6";
   171             break;
   172         case SDLK_F7:
   173             SDL_keynames[i] = "f7";
   174             break;
   175         case SDLK_F8:
   176             SDL_keynames[i] = "f8";
   177             break;
   178         case SDLK_F9:
   179             SDL_keynames[i] = "f9";
   180             break;
   181         case SDLK_F10:
   182             SDL_keynames[i] = "f10";
   183             break;
   184         case SDLK_F11:
   185             SDL_keynames[i] = "f11";
   186             break;
   187         case SDLK_F12:
   188             SDL_keynames[i] = "f12";
   189             break;
   190         case SDLK_F13:
   191             SDL_keynames[i] = "f13";
   192             break;
   193         case SDLK_F14:
   194             SDL_keynames[i] = "f14";
   195             break;
   196         case SDLK_F15:
   197             SDL_keynames[i] = "f15";
   198             break;
   199 
   200         case SDLK_NUMLOCK:
   201             SDL_keynames[i] = "numlock";
   202             break;
   203         case SDLK_CAPSLOCK:
   204             SDL_keynames[i] = "caps lock";
   205             break;
   206         case SDLK_SCROLLOCK:
   207             SDL_keynames[i] = "scroll lock";
   208             break;
   209         case SDLK_RSHIFT:
   210             SDL_keynames[i] = "right shift";
   211             break;
   212         case SDLK_LSHIFT:
   213             SDL_keynames[i] = "left shift";
   214             break;
   215         case SDLK_RCTRL:
   216             SDL_keynames[i] = "right ctrl";
   217             break;
   218         case SDLK_LCTRL:
   219             SDL_keynames[i] = "left ctrl";
   220             break;
   221         case SDLK_RALT:
   222             SDL_keynames[i] = "right alt";
   223             break;
   224         case SDLK_LALT:
   225             SDL_keynames[i] = "left alt";
   226             break;
   227         case SDLK_RMETA:
   228             SDL_keynames[i] = "right meta";
   229             break;
   230         case SDLK_LMETA:
   231             SDL_keynames[i] = "left meta";
   232             break;
   233         case SDLK_LSUPER:
   234             SDL_keynames[i] = "left super";     /* "Windows" keys */
   235             break;
   236         case SDLK_RSUPER:
   237             SDL_keynames[i] = "right super";
   238             break;
   239         case SDLK_MODE:
   240             SDL_keynames[i] = "alt gr";
   241             break;
   242         case SDLK_COMPOSE:
   243             SDL_keynames[i] = "compose";
   244             break;
   245 
   246         case SDLK_HELP:
   247             SDL_keynames[i] = "help";
   248             break;
   249         case SDLK_PRINT:
   250             SDL_keynames[i] = "print screen";
   251             break;
   252         case SDLK_SYSREQ:
   253             SDL_keynames[i] = "sys req";
   254             break;
   255         case SDLK_BREAK:
   256             SDL_keynames[i] = "break";
   257             break;
   258         case SDLK_MENU:
   259             SDL_keynames[i] = "menu";
   260             break;
   261         case SDLK_POWER:
   262             SDL_keynames[i] = "power";
   263             break;
   264         case SDLK_EURO:
   265             SDL_keynames[i] = "euro";
   266             break;
   267         case SDLK_UNDO:
   268             SDL_keynames[i] = "undo";
   269             break;
   270 
   271         default:
   272             SDL_keynames[i] = NULL;
   273             break;
   274         }
   275     }
   276 
   277     /* Done.  Whew. */
   278     return (0);
   279 }
   280 
   281 SDL_Keyboard *
   282 SDL_GetKeyboard(int index)
   283 {
   284     if (index < 0 || index >= SDL_num_keyboards) {
   285         return NULL;
   286     }
   287     return SDL_keyboards[index];
   288 }
   289 
   290 int
   291 SDL_AddKeyboard(const SDL_Keyboard * keyboard, int index)
   292 {
   293     SDL_Keyboard **keyboards;
   294 
   295     /* Add the keyboard to the list of keyboards */
   296     if (index < 0 || index >= SDL_num_keyboards || SDL_keyboards[index]) {
   297         keyboards =
   298             (SDL_Keyboard **) SDL_realloc(SDL_keyboards,
   299                                           (SDL_num_keyboards +
   300                                            1) * sizeof(*keyboards));
   301         if (!keyboards) {
   302             SDL_OutOfMemory();
   303             return -1;
   304         }
   305 
   306         SDL_keyboards = keyboards;
   307         index = SDL_num_keyboards++;
   308     }
   309     SDL_keyboards[index] =
   310         (SDL_Keyboard *) SDL_malloc(sizeof(*SDL_keyboards[index]));
   311     if (!SDL_keyboards[index]) {
   312         SDL_OutOfMemory();
   313         return -1;
   314     }
   315     *SDL_keyboards[index] = *keyboard;
   316 
   317     return index;
   318 }
   319 
   320 void
   321 SDL_DelKeyboard(int index)
   322 {
   323     SDL_Keyboard *keyboard = SDL_GetKeyboard(index);
   324 
   325     if (!keyboard) {
   326         return;
   327     }
   328 
   329     if (keyboard->FreeKeyboard) {
   330         keyboard->FreeKeyboard(keyboard);
   331     }
   332     SDL_free(keyboard);
   333 
   334     SDL_keyboards[index] = NULL;
   335 }
   336 
   337 void
   338 SDL_ResetKeyboard(int index)
   339 {
   340     SDL_Keyboard *keyboard = SDL_GetKeyboard(index);
   341     SDLKey key;
   342 
   343     if (!keyboard) {
   344         return;
   345     }
   346 
   347     for (key = SDLK_FIRST; key < SDLK_LAST; ++key) {
   348         if (keyboard->keystate[key] == SDL_PRESSED) {
   349             SDL_SendKeyboardKey(index, SDL_RELEASED, 0, key);
   350         }
   351     }
   352     keyboard->repeat.timestamp = 0;
   353 }
   354 
   355 void
   356 SDL_KeyboardQuit(void)
   357 {
   358     int i;
   359 
   360     for (i = 0; i < SDL_num_keyboards; ++i) {
   361         SDL_DelKeyboard(i);
   362     }
   363     SDL_num_keyboards = 0;
   364     SDL_current_keyboard = 0;
   365 
   366     if (SDL_keyboards) {
   367         SDL_free(SDL_keyboards);
   368         SDL_keyboards = NULL;
   369     }
   370 }
   371 
   372 int
   373 SDL_GetNumKeyboards(void)
   374 {
   375     return SDL_num_keyboards;
   376 }
   377 
   378 int
   379 SDL_SelectKeyboard(int index)
   380 {
   381     if (index >= 0 && index < SDL_num_keyboards) {
   382         SDL_current_keyboard = index;
   383     }
   384     return SDL_current_keyboard;
   385 }
   386 
   387 int
   388 SDL_EnableUNICODE(int enable)
   389 {
   390     int old_mode;
   391 
   392     old_mode = SDL_TranslateUNICODE;
   393     if (enable >= 0) {
   394         SDL_TranslateUNICODE = enable;
   395     }
   396     return (old_mode);
   397 }
   398 
   399 Uint8 *
   400 SDL_GetKeyState(int *numkeys)
   401 {
   402     SDL_Keyboard *keyboard = SDL_GetKeyboard(SDL_current_keyboard);
   403 
   404     if (numkeys != (int *) 0) {
   405         *numkeys = SDLK_LAST;
   406     }
   407 
   408     if (!keyboard) {
   409         return NULL;
   410     }
   411     return keyboard->keystate;
   412 }
   413 
   414 SDLMod
   415 SDL_GetModState(void)
   416 {
   417     SDL_Keyboard *keyboard = SDL_GetKeyboard(SDL_current_keyboard);
   418 
   419     if (!keyboard) {
   420         return KMOD_NONE;
   421     }
   422     return keyboard->modstate;
   423 }
   424 
   425 void
   426 SDL_SetModState(SDLMod modstate)
   427 {
   428     SDL_Keyboard *keyboard = SDL_GetKeyboard(SDL_current_keyboard);
   429 
   430     if (!keyboard) {
   431         return;
   432     }
   433     keyboard->modstate = modstate;
   434 }
   435 
   436 const char *
   437 SDL_GetKeyName(SDLKey key)
   438 {
   439     const char *keyname;
   440 
   441     if (key < SDL_arraysize(SDL_keynames)) {
   442         keyname = SDL_keynames[key];
   443     } else {
   444         keyname = NULL;
   445     }
   446     if (keyname == NULL) {
   447         if (key < 256) {
   448             static char temp[4];
   449             char *cvt;
   450             temp[0] = (char) key;
   451             temp[1] = '\0';
   452             cvt = SDL_iconv_string("UTF-8", "LATIN1", temp, 1);
   453             SDL_strlcpy(temp, cvt, SDL_arraysize(temp));
   454             SDL_free(cvt);
   455             keyname = temp;
   456         } else {
   457             keyname = "unknown key";
   458         }
   459     }
   460     return keyname;
   461 }
   462 
   463 void
   464 SDL_SetKeyboardFocus(int index, SDL_WindowID windowID)
   465 {
   466     SDL_Keyboard *keyboard = SDL_GetKeyboard(index);
   467     int i;
   468     SDL_bool focus;
   469 
   470     if (!keyboard || (keyboard->focus == windowID)) {
   471         return;
   472     }
   473 
   474     /* See if the current window has lost focus */
   475     if (keyboard->focus) {
   476         focus = SDL_FALSE;
   477         for (i = 0; i < SDL_num_keyboards; ++i) {
   478             SDL_Keyboard *check;
   479             if (i != index) {
   480                 check = SDL_GetKeyboard(i);
   481                 if (check && check->focus == keyboard->focus) {
   482                     focus = SDL_TRUE;
   483                     break;
   484                 }
   485             }
   486         }
   487         if (!focus) {
   488             SDL_SendWindowEvent(windowID, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0);
   489         }
   490     }
   491 
   492     keyboard->focus = windowID;
   493 
   494     if (keyboard->focus) {
   495         focus = SDL_FALSE;
   496         for (i = 0; i < SDL_num_keyboards; ++i) {
   497             SDL_Keyboard *check;
   498             if (i != index) {
   499                 check = SDL_GetKeyboard(i);
   500                 if (check && check->focus == keyboard->focus) {
   501                     focus = SDL_TRUE;
   502                     break;
   503                 }
   504             }
   505         }
   506         if (!focus) {
   507             SDL_SendWindowEvent(windowID, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
   508         }
   509     }
   510 }
   511 
   512 int
   513 SDL_SendKeyboardKey(int index, Uint8 state, Uint8 scancode, SDLKey key)
   514 {
   515     SDL_Keyboard *keyboard = SDL_GetKeyboard(index);
   516     int posted, repeatable;
   517     Uint16 modstate;
   518     Uint8 type;
   519 
   520     if (!keyboard) {
   521         return 0;
   522     }
   523 #if 0
   524     printf("The '%s' key has been %s\n", SDL_GetKeyName(key),
   525            state == SDL_PRESSED ? "pressed" : "released");
   526 #endif
   527     repeatable = 0;
   528     if (state == SDL_PRESSED) {
   529         modstate = keyboard->modstate;
   530         switch (key) {
   531         case SDLK_UNKNOWN:
   532             break;
   533         case SDLK_NUMLOCK:
   534             keyboard->modstate ^= KMOD_NUM;
   535             break;
   536         case SDLK_CAPSLOCK:
   537             keyboard->modstate ^= KMOD_CAPS;
   538             break;
   539         case SDLK_LCTRL:
   540             keyboard->modstate |= KMOD_LCTRL;
   541             break;
   542         case SDLK_RCTRL:
   543             keyboard->modstate |= KMOD_RCTRL;
   544             break;
   545         case SDLK_LSHIFT:
   546             keyboard->modstate |= KMOD_LSHIFT;
   547             break;
   548         case SDLK_RSHIFT:
   549             keyboard->modstate |= KMOD_RSHIFT;
   550             break;
   551         case SDLK_LALT:
   552             keyboard->modstate |= KMOD_LALT;
   553             break;
   554         case SDLK_RALT:
   555             keyboard->modstate |= KMOD_RALT;
   556             break;
   557         case SDLK_LMETA:
   558             keyboard->modstate |= KMOD_LMETA;
   559             break;
   560         case SDLK_RMETA:
   561             keyboard->modstate |= KMOD_RMETA;
   562             break;
   563         case SDLK_MODE:
   564             keyboard->modstate |= KMOD_MODE;
   565             break;
   566         default:
   567             repeatable = 1;
   568             break;
   569         }
   570     } else {
   571         switch (key) {
   572         case SDLK_UNKNOWN:
   573             break;
   574         case SDLK_NUMLOCK:
   575         case SDLK_CAPSLOCK:
   576             break;
   577         case SDLK_LCTRL:
   578             keyboard->modstate &= ~KMOD_LCTRL;
   579             break;
   580         case SDLK_RCTRL:
   581             keyboard->modstate &= ~KMOD_RCTRL;
   582             break;
   583         case SDLK_LSHIFT:
   584             keyboard->modstate &= ~KMOD_LSHIFT;
   585             break;
   586         case SDLK_RSHIFT:
   587             keyboard->modstate &= ~KMOD_RSHIFT;
   588             break;
   589         case SDLK_LALT:
   590             keyboard->modstate &= ~KMOD_LALT;
   591             break;
   592         case SDLK_RALT:
   593             keyboard->modstate &= ~KMOD_RALT;
   594             break;
   595         case SDLK_LMETA:
   596             keyboard->modstate &= ~KMOD_LMETA;
   597             break;
   598         case SDLK_RMETA:
   599             keyboard->modstate &= ~KMOD_RMETA;
   600             break;
   601         case SDLK_MODE:
   602             keyboard->modstate &= ~KMOD_MODE;
   603             break;
   604         default:
   605             break;
   606         }
   607         modstate = keyboard->modstate;
   608     }
   609 
   610     /* Figure out what type of event this is */
   611     switch (state) {
   612     case SDL_PRESSED:
   613         type = SDL_KEYDOWN;
   614         break;
   615     case SDL_RELEASED:
   616         type = SDL_KEYUP;
   617         /*
   618          * jk 991215 - Added
   619          */
   620         if (keyboard->repeat.timestamp &&
   621             keyboard->repeat.evt.key.keysym.sym == key) {
   622             keyboard->repeat.timestamp = 0;
   623         }
   624         break;
   625     default:
   626         /* Invalid state -- bail */
   627         return 0;
   628     }
   629 
   630     if (key != SDLK_UNKNOWN) {
   631         /* Drop events that don't change state */
   632         if (keyboard->keystate[key] == state) {
   633 #if 0
   634             printf("Keyboard event didn't change state - dropped!\n");
   635 #endif
   636             return 0;
   637         }
   638 
   639         /* Update internal keyboard state */
   640         keyboard->keystate[key] = state;
   641     }
   642 
   643     /* Post the event, if desired */
   644     posted = 0;
   645     if (SDL_ProcessEvents[type] == SDL_ENABLE) {
   646         SDL_Event event;
   647         event.key.type = type;
   648         event.key.which = (Uint8) index;
   649         event.key.state = state;
   650         event.key.keysym.scancode = scancode;
   651         event.key.keysym.sym = (Uint16) key;
   652         event.key.keysym.mod = modstate;
   653         event.key.keysym.unicode = 0;
   654         event.key.windowID = keyboard->focus;
   655         /*
   656          * jk 991215 - Added
   657          */
   658         if (repeatable && (keyboard->repeat.delay != 0)) {
   659             Uint32 timestamp = SDL_GetTicks();
   660             if (!timestamp) {
   661                 timestamp = 1;
   662             }
   663             keyboard->repeat.evt = event;
   664             keyboard->repeat.firsttime = 1;
   665             keyboard->repeat.timestamp = 1;
   666         }
   667         posted = (SDL_PushEvent(&event) > 0);
   668     }
   669     return (posted);
   670 }
   671 
   672 int
   673 SDL_SendKeyboardText(int index, const char *text)
   674 {
   675     SDL_Keyboard *keyboard = SDL_GetKeyboard(index);
   676     int posted;
   677 
   678     if (!keyboard) {
   679         return 0;
   680     }
   681 
   682     /* Post the event, if desired */
   683     posted = 0;
   684     if (SDL_ProcessEvents[SDL_TEXTINPUT] == SDL_ENABLE) {
   685         SDL_Event event;
   686         event.text.type = SDL_TEXTINPUT;
   687         event.text.which = (Uint8) index;
   688         SDL_strlcpy(event.text.text, text, SDL_arraysize(event.text.text));
   689         event.key.windowID = keyboard->focus;
   690         posted = (SDL_PushEvent(&event) > 0);
   691     }
   692     return (posted);
   693 }
   694 
   695 /*
   696  * jk 991215 - Added
   697  */
   698 void
   699 SDL_CheckKeyRepeat(void)
   700 {
   701     int i;
   702 
   703     for (i = 0; i < SDL_num_keyboards; ++i) {
   704         SDL_Keyboard *keyboard = SDL_keyboards[i];
   705 
   706         if (!keyboard) {
   707             continue;
   708         }
   709 
   710         if (keyboard->repeat.timestamp) {
   711             Uint32 now, interval;
   712 
   713             now = SDL_GetTicks();
   714             interval = (now - keyboard->repeat.timestamp);
   715             if (keyboard->repeat.firsttime) {
   716                 if (interval > (Uint32) keyboard->repeat.delay) {
   717                     keyboard->repeat.timestamp = now;
   718                     keyboard->repeat.firsttime = 0;
   719                 }
   720             } else {
   721                 if (interval > (Uint32) keyboard->repeat.interval) {
   722                     keyboard->repeat.timestamp = now;
   723                     SDL_PushEvent(&keyboard->repeat.evt);
   724                 }
   725             }
   726         }
   727     }
   728 }
   729 
   730 int
   731 SDL_EnableKeyRepeat(int delay, int interval)
   732 {
   733     SDL_Keyboard *keyboard = SDL_GetKeyboard(SDL_current_keyboard);
   734 
   735     if (!keyboard) {
   736         SDL_SetError("No keyboard is currently selected");
   737         return -1;
   738     }
   739 
   740     if ((delay < 0) || (interval < 0)) {
   741         SDL_SetError("keyboard repeat value less than zero");
   742         return -1;
   743     }
   744 
   745     keyboard->repeat.firsttime = 0;
   746     keyboard->repeat.delay = delay;
   747     keyboard->repeat.interval = interval;
   748     keyboard->repeat.timestamp = 0;
   749 
   750     return 0;
   751 }
   752 
   753 void
   754 SDL_GetKeyRepeat(int *delay, int *interval)
   755 {
   756     SDL_Keyboard *keyboard = SDL_GetKeyboard(SDL_current_keyboard);
   757 
   758     if (!keyboard) {
   759         if (delay) {
   760             *delay = 0;
   761         }
   762         if (interval) {
   763             *interval = 0;
   764         }
   765         return;
   766     }
   767     if (delay) {
   768         *delay = keyboard->repeat.delay;
   769     }
   770     if (interval) {
   771         *interval = keyboard->repeat.interval;
   772     }
   773 }
   774 
   775 /* vi: set ts=4 sw=4 expandtab: */