Mercurial > sdl-ios-xcode
comparison src/video/cocoa/SDL_cocoakeyboard.m @ 4565:e2d46c5c7483
Fixed key repeat detection on X11, and simplified the code for everyone else.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 21 Jul 2010 21:47:12 -0700 |
parents | 95352c671a6e |
children | 8c229370ddba |
comparison
equal
deleted
inserted
replaced
4563:ffd169948438 | 4565:e2d46c5c7483 |
---|---|
217 newMask = newMods & bit; | 217 newMask = newMods & bit; |
218 | 218 |
219 if (oldMask && oldMask != newMask) { /* modifier up event */ | 219 if (oldMask && oldMask != newMask) { /* modifier up event */ |
220 /* If this was Caps Lock, we need some additional voodoo to make SDL happy */ | 220 /* If this was Caps Lock, we need some additional voodoo to make SDL happy */ |
221 if (bit == NSAlphaShiftKeyMask) { | 221 if (bit == NSAlphaShiftKeyMask) { |
222 SDL_SendKeyboardKey(SDL_PRESSED, mapping[i], SDL_FALSE); | 222 SDL_SendKeyboardKey(SDL_PRESSED, mapping[i]); |
223 } | 223 } |
224 SDL_SendKeyboardKey(SDL_RELEASED, mapping[i], SDL_FALSE); | 224 SDL_SendKeyboardKey(SDL_RELEASED, mapping[i]); |
225 } else if (newMask && oldMask != newMask) { /* modifier down event */ | 225 } else if (newMask && oldMask != newMask) { /* modifier down event */ |
226 SDL_SendKeyboardKey(SDL_PRESSED, mapping[i], SDL_FALSE); | 226 SDL_SendKeyboardKey(SDL_PRESSED, mapping[i]); |
227 /* If this was Caps Lock, we need some additional voodoo to make SDL happy */ | 227 /* If this was Caps Lock, we need some additional voodoo to make SDL happy */ |
228 if (bit == NSAlphaShiftKeyMask) { | 228 if (bit == NSAlphaShiftKeyMask) { |
229 SDL_SendKeyboardKey(SDL_RELEASED, mapping[i], SDL_FALSE); | 229 SDL_SendKeyboardKey(SDL_RELEASED, mapping[i]); |
230 } | 230 } |
231 } | 231 } |
232 } | 232 } |
233 } | 233 } |
234 | 234 |
249 */ | 249 */ |
250 oldMask = oldMods & device_independent_mask; | 250 oldMask = oldMods & device_independent_mask; |
251 newMask = newMods & device_independent_mask; | 251 newMask = newMods & device_independent_mask; |
252 | 252 |
253 if (oldMask && oldMask != newMask) { | 253 if (oldMask && oldMask != newMask) { |
254 SDL_SendKeyboardKey(SDL_RELEASED, scancode, SDL_FALSE); | 254 SDL_SendKeyboardKey(SDL_RELEASED, scancode); |
255 } else if (newMask && oldMask != newMask) { | 255 } else if (newMask && oldMask != newMask) { |
256 SDL_SendKeyboardKey(SDL_PRESSED, scancode, SDL_FALSE); | 256 SDL_SendKeyboardKey(SDL_PRESSED, scancode); |
257 } | 257 } |
258 } | 258 } |
259 | 259 |
260 /* This is a helper function for HandleModifierSide. | 260 /* This is a helper function for HandleModifierSide. |
261 * This function sets the actual SDL_PrivateKeyboard event. | 261 * This function sets the actual SDL_PrivateKeyboard event. |
276 /* We now know that this side bit flipped. But we don't know if | 276 /* We now know that this side bit flipped. But we don't know if |
277 * it went pressed to released or released to pressed, so we must | 277 * it went pressed to released or released to pressed, so we must |
278 * find out which it is. | 278 * find out which it is. |
279 */ | 279 */ |
280 if (new_dep_mask && old_dep_mask != new_dep_mask) { | 280 if (new_dep_mask && old_dep_mask != new_dep_mask) { |
281 SDL_SendKeyboardKey(SDL_PRESSED, scancode, SDL_FALSE); | 281 SDL_SendKeyboardKey(SDL_PRESSED, scancode); |
282 } else { | 282 } else { |
283 SDL_SendKeyboardKey(SDL_RELEASED, scancode, SDL_FALSE); | 283 SDL_SendKeyboardKey(SDL_RELEASED, scancode); |
284 } | 284 } |
285 } | 285 } |
286 | 286 |
287 /* This is a helper function for DoSidedModifiers. | 287 /* This is a helper function for DoSidedModifiers. |
288 * This function will figure out if the modifier key is the left or right side, | 288 * This function will figure out if the modifier key is the left or right side, |
349 */ | 349 */ |
350 if ((device_dependent_mask & oldMods) == 0) { | 350 if ((device_dependent_mask & oldMods) == 0) { |
351 /* In this case, we can't detect the keyboard, so use the left side | 351 /* In this case, we can't detect the keyboard, so use the left side |
352 * to represent both, and release it. | 352 * to represent both, and release it. |
353 */ | 353 */ |
354 SDL_SendKeyboardKey(SDL_RELEASED, left_scancode, SDL_FALSE); | 354 SDL_SendKeyboardKey(SDL_RELEASED, left_scancode); |
355 return; | 355 return; |
356 } | 356 } |
357 | 357 |
358 /* | 358 /* |
359 * This could have been done in an if-else case because at this point, | 359 * This could have been done in an if-else case because at this point, |
360 * we know that all keys have been released when calling this function. | 360 * we know that all keys have been released when calling this function. |
361 * But I'm being paranoid so I want to handle each separately, | 361 * But I'm being paranoid so I want to handle each separately, |
362 * so I hope this doesn't cause other problems. | 362 * so I hope this doesn't cause other problems. |
363 */ | 363 */ |
364 if ( left_device_dependent_mask & oldMods ) { | 364 if ( left_device_dependent_mask & oldMods ) { |
365 SDL_SendKeyboardKey(SDL_RELEASED, left_scancode, SDL_FALSE); | 365 SDL_SendKeyboardKey(SDL_RELEASED, left_scancode); |
366 } | 366 } |
367 if ( right_device_dependent_mask & oldMods ) { | 367 if ( right_device_dependent_mask & oldMods ) { |
368 SDL_SendKeyboardKey(SDL_RELEASED, right_scancode, SDL_FALSE); | 368 SDL_SendKeyboardKey(SDL_RELEASED, right_scancode); |
369 } | 369 } |
370 } | 370 } |
371 | 371 |
372 /* This is a helper function for DoSidedModifiers. | 372 /* This is a helper function for DoSidedModifiers. |
373 * This function handles the CapsLock case. | 373 * This function handles the CapsLock case. |
380 | 380 |
381 oldMask = oldMods & NSAlphaShiftKeyMask; | 381 oldMask = oldMods & NSAlphaShiftKeyMask; |
382 newMask = newMods & NSAlphaShiftKeyMask; | 382 newMask = newMods & NSAlphaShiftKeyMask; |
383 | 383 |
384 if (oldMask != newMask) { | 384 if (oldMask != newMask) { |
385 SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_CAPSLOCK, SDL_FALSE); | 385 SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_CAPSLOCK); |
386 SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_CAPSLOCK, SDL_FALSE); | 386 SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_CAPSLOCK); |
387 } | 387 } |
388 | 388 |
389 oldMask = oldMods & NSNumericPadKeyMask; | 389 oldMask = oldMods & NSNumericPadKeyMask; |
390 newMask = newMods & NSNumericPadKeyMask; | 390 newMask = newMods & NSNumericPadKeyMask; |
391 | 391 |
392 if (oldMask != newMask) { | 392 if (oldMask != newMask) { |
393 SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_NUMLOCKCLEAR, SDL_FALSE); | 393 SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_NUMLOCKCLEAR); |
394 SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_NUMLOCKCLEAR, SDL_FALSE); | 394 SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_NUMLOCKCLEAR); |
395 } | 395 } |
396 } | 396 } |
397 | 397 |
398 /* This function will handle the modifier keys and also determine the | 398 /* This function will handle the modifier keys and also determine the |
399 * correct side of the key. | 399 * correct side of the key. |
668 Cocoa_HandleKeyEvent(_THIS, NSEvent *event) | 668 Cocoa_HandleKeyEvent(_THIS, NSEvent *event) |
669 { | 669 { |
670 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; | 670 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; |
671 unsigned short scancode = [event keyCode]; | 671 unsigned short scancode = [event keyCode]; |
672 SDL_scancode code; | 672 SDL_scancode code; |
673 SDL_bool repeat; | |
674 #if 0 | 673 #if 0 |
675 const char *text; | 674 const char *text; |
676 #endif | 675 #endif |
677 | 676 |
678 if ((scancode == 10 || scancode == 50) && KBGetLayoutType(LMGetKbdType()) == kKeyboardISO) { | 677 if ((scancode == 10 || scancode == 50) && KBGetLayoutType(LMGetKbdType()) == kKeyboardISO) { |
687 code = SDL_SCANCODE_UNKNOWN; | 686 code = SDL_SCANCODE_UNKNOWN; |
688 } | 687 } |
689 | 688 |
690 switch ([event type]) { | 689 switch ([event type]) { |
691 case NSKeyDown: | 690 case NSKeyDown: |
692 repeat = [event isARepeat] ? SDL_TRUE : SDL_FALSE; | 691 if (![event isARepeat]) { |
693 if (!repeat) { | |
694 /* See if we need to rebuild the keyboard layout */ | 692 /* See if we need to rebuild the keyboard layout */ |
695 UpdateKeymap(data); | 693 UpdateKeymap(data); |
696 } | 694 } |
697 | 695 |
698 SDL_SendKeyboardKey(SDL_PRESSED, code, repeat); | 696 SDL_SendKeyboardKey(SDL_PRESSED, code); |
699 #if 1 | 697 #if 1 |
700 if (code == SDL_SCANCODE_UNKNOWN) { | 698 if (code == SDL_SCANCODE_UNKNOWN) { |
701 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); | 699 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); |
702 } | 700 } |
703 #endif | 701 #endif |
712 } | 710 } |
713 #endif | 711 #endif |
714 } | 712 } |
715 break; | 713 break; |
716 case NSKeyUp: | 714 case NSKeyUp: |
717 SDL_SendKeyboardKey(SDL_RELEASED, code, SDL_FALSE); | 715 SDL_SendKeyboardKey(SDL_RELEASED, code); |
718 break; | 716 break; |
719 case NSFlagsChanged: | 717 case NSFlagsChanged: |
720 /* FIXME CW 2007-08-14: check if this whole mess that takes up half of this file is really necessary */ | 718 /* FIXME CW 2007-08-14: check if this whole mess that takes up half of this file is really necessary */ |
721 HandleModifiers(_this, scancode, [event modifierFlags]); | 719 HandleModifiers(_this, scancode, [event modifierFlags]); |
722 break; | 720 break; |