diff src/video/cocoa/SDL_cocoakeyboard.m @ 4560:95352c671a6e

Added support for keyboard repeat (only tested on Windows so far)
author Sam Lantinga <slouken@libsdl.org>
date Tue, 20 Jul 2010 23:25:24 -0700
parents 3d91e31fcf71
children e2d46c5c7483
line wrap: on
line diff
--- a/src/video/cocoa/SDL_cocoakeyboard.m	Tue Jul 20 00:57:01 2010 -0700
+++ b/src/video/cocoa/SDL_cocoakeyboard.m	Tue Jul 20 23:25:24 2010 -0700
@@ -219,14 +219,14 @@
         if (oldMask && oldMask != newMask) {        /* modifier up event */
             /* If this was Caps Lock, we need some additional voodoo to make SDL happy */
             if (bit == NSAlphaShiftKeyMask) {
-                SDL_SendKeyboardKey(SDL_PRESSED, mapping[i]);
+                SDL_SendKeyboardKey(SDL_PRESSED, mapping[i], SDL_FALSE);
             }
-            SDL_SendKeyboardKey(SDL_RELEASED, mapping[i]);
+            SDL_SendKeyboardKey(SDL_RELEASED, mapping[i], SDL_FALSE);
         } else if (newMask && oldMask != newMask) { /* modifier down event */
-            SDL_SendKeyboardKey(SDL_PRESSED, mapping[i]);
+            SDL_SendKeyboardKey(SDL_PRESSED, mapping[i], SDL_FALSE);
             /* If this was Caps Lock, we need some additional voodoo to make SDL happy */
             if (bit == NSAlphaShiftKeyMask) {
-                SDL_SendKeyboardKey(SDL_RELEASED, mapping[i]);
+                SDL_SendKeyboardKey(SDL_RELEASED, mapping[i], SDL_FALSE);
             }
         }
     }
@@ -251,9 +251,9 @@
     newMask = newMods & device_independent_mask;
     
     if (oldMask && oldMask != newMask) {
-        SDL_SendKeyboardKey(SDL_RELEASED, scancode);
+        SDL_SendKeyboardKey(SDL_RELEASED, scancode, SDL_FALSE);
     } else if (newMask && oldMask != newMask) {
-        SDL_SendKeyboardKey(SDL_PRESSED, scancode);
+        SDL_SendKeyboardKey(SDL_PRESSED, scancode, SDL_FALSE);
     }
 }
 
@@ -278,9 +278,9 @@
      * find out which it is.
      */
     if (new_dep_mask && old_dep_mask != new_dep_mask) {
-        SDL_SendKeyboardKey(SDL_PRESSED, scancode);
+        SDL_SendKeyboardKey(SDL_PRESSED, scancode, SDL_FALSE);
     } else {
-        SDL_SendKeyboardKey(SDL_RELEASED, scancode);
+        SDL_SendKeyboardKey(SDL_RELEASED, scancode, SDL_FALSE);
     }
 }
 
@@ -351,7 +351,7 @@
         /* In this case, we can't detect the keyboard, so use the left side 
          * to represent both, and release it. 
          */
-        SDL_SendKeyboardKey(SDL_RELEASED, left_scancode);
+        SDL_SendKeyboardKey(SDL_RELEASED, left_scancode, SDL_FALSE);
         return;
     }
 
@@ -362,10 +362,10 @@
      * so I hope this doesn't cause other problems.
      */
     if ( left_device_dependent_mask & oldMods ) {
-        SDL_SendKeyboardKey(SDL_RELEASED, left_scancode);
+        SDL_SendKeyboardKey(SDL_RELEASED, left_scancode, SDL_FALSE);
     }
     if ( right_device_dependent_mask & oldMods ) {
-        SDL_SendKeyboardKey(SDL_RELEASED, right_scancode);
+        SDL_SendKeyboardKey(SDL_RELEASED, right_scancode, SDL_FALSE);
     }
 }
 
@@ -382,16 +382,16 @@
     newMask = newMods & NSAlphaShiftKeyMask;
 
     if (oldMask != newMask) {
-        SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_CAPSLOCK);
-        SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_CAPSLOCK);
+        SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_CAPSLOCK, SDL_FALSE);
+        SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_CAPSLOCK, SDL_FALSE);
     }
 
     oldMask = oldMods & NSNumericPadKeyMask;
     newMask = newMods & NSNumericPadKeyMask;
 
     if (oldMask != newMask) {
-        SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_NUMLOCKCLEAR);
-        SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_NUMLOCKCLEAR);
+        SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_NUMLOCKCLEAR, SDL_FALSE);
+        SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_NUMLOCKCLEAR, SDL_FALSE);
     }
 }
 
@@ -670,6 +670,7 @@
     SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
     unsigned short scancode = [event keyCode];
     SDL_scancode code;
+    SDL_bool repeat;
 #if 0
     const char *text;
 #endif
@@ -688,17 +689,18 @@
 
     switch ([event type]) {
     case NSKeyDown:
-        if (![event isARepeat]) {
+        repeat = [event isARepeat] ? SDL_TRUE : SDL_FALSE;
+        if (!repeat) {
             /* See if we need to rebuild the keyboard layout */
             UpdateKeymap(data);
+        }
 
-            SDL_SendKeyboardKey(SDL_PRESSED, code);
+        SDL_SendKeyboardKey(SDL_PRESSED, code, repeat);
 #if 1
-            if (code == SDL_SCANCODE_UNKNOWN) {
-                fprintf(stderr, "The key you just pressed is not recognized by SDL. To help get this fixed, report this to the SDL mailing list <sdl@libsdl.org> or to Christian Walther <cwalther@gmx.ch>. Mac virtual key code is %d.\n", scancode);
-            }
+        if (code == SDL_SCANCODE_UNKNOWN) {
+            fprintf(stderr, "The key you just pressed is not recognized by SDL. To help get this fixed, report this to the SDL mailing list <sdl@libsdl.org> or to Christian Walther <cwalther@gmx.ch>. Mac virtual key code is %d.\n", scancode);
+        }
 #endif
-        }
         if (SDL_EventState(SDL_TEXTINPUT, SDL_QUERY)) {
             /* FIXME CW 2007-08-16: only send those events to the field editor for which we actually want text events, not e.g. esc or function keys. Arrow keys in particular seem to produce crashes sometimes. */
             [data->fieldEdit interpretKeyEvents:[NSArray arrayWithObject:event]];
@@ -712,7 +714,7 @@
         }
         break;
     case NSKeyUp:
-        SDL_SendKeyboardKey(SDL_RELEASED, code);
+        SDL_SendKeyboardKey(SDL_RELEASED, code, SDL_FALSE);
         break;
     case NSFlagsChanged:
         /* FIXME CW 2007-08-14: check if this whole mess that takes up half of this file is really necessary */