comparison src/events/SDL_keyboard.c @ 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 dc9d77a26388
children 1d7ea8724f4a
comparison
equal deleted inserted replaced
4563:ffd169948438 4565:e2d46c5c7483
564 SDL_Keyboard *keyboard = &SDL_keyboard; 564 SDL_Keyboard *keyboard = &SDL_keyboard;
565 SDL_scancode scancode; 565 SDL_scancode scancode;
566 566
567 for (scancode = 0; scancode < SDL_NUM_SCANCODES; ++scancode) { 567 for (scancode = 0; scancode < SDL_NUM_SCANCODES; ++scancode) {
568 if (keyboard->keystate[scancode] == SDL_PRESSED) { 568 if (keyboard->keystate[scancode] == SDL_PRESSED) {
569 SDL_SendKeyboardKey(SDL_RELEASED, scancode, SDL_FALSE); 569 SDL_SendKeyboardKey(SDL_RELEASED, scancode);
570 } 570 }
571 } 571 }
572 } 572 }
573 573
574 void 574 void
625 } 625 }
626 } 626 }
627 } 627 }
628 628
629 int 629 int
630 SDL_SendKeyboardKey(Uint8 state, SDL_scancode scancode, SDL_bool repeat) 630 SDL_SendKeyboardKey(Uint8 state, SDL_scancode scancode)
631 { 631 {
632 SDL_Keyboard *keyboard = &SDL_keyboard; 632 SDL_Keyboard *keyboard = &SDL_keyboard;
633 int posted; 633 int posted;
634 Uint16 modstate; 634 Uint16 modstate;
635 Uint32 type; 635 Uint32 type;
636 Uint8 repeat;
636 637
637 if (!scancode) { 638 if (!scancode) {
638 return 0; 639 return 0;
639 } 640 }
640 #if 0 641 #if 0
730 /* Invalid state -- bail */ 731 /* Invalid state -- bail */
731 return 0; 732 return 0;
732 } 733 }
733 734
734 /* Drop events that don't change state */ 735 /* Drop events that don't change state */
736 repeat = (state && keyboard->keystate[scancode]);
735 if (keyboard->keystate[scancode] == state && !repeat) { 737 if (keyboard->keystate[scancode] == state && !repeat) {
736 #if 0 738 #if 0
737 printf("Keyboard event didn't change state - dropped!\n"); 739 printf("Keyboard event didn't change state - dropped!\n");
738 #endif 740 #endif
739 return 0; 741 return 0;
746 posted = 0; 748 posted = 0;
747 if (SDL_GetEventState(type) == SDL_ENABLE) { 749 if (SDL_GetEventState(type) == SDL_ENABLE) {
748 SDL_Event event; 750 SDL_Event event;
749 event.key.type = type; 751 event.key.type = type;
750 event.key.state = state; 752 event.key.state = state;
751 event.key.repeat = repeat ? 1 : 0; 753 event.key.repeat = repeat;
752 event.key.keysym.scancode = scancode; 754 event.key.keysym.scancode = scancode;
753 event.key.keysym.sym = keyboard->keymap[scancode]; 755 event.key.keysym.sym = keyboard->keymap[scancode];
754 event.key.keysym.mod = modstate; 756 event.key.keysym.mod = modstate;
755 event.key.keysym.unicode = 0; 757 event.key.keysym.unicode = 0;
756 event.key.windowID = keyboard->focus ? keyboard->focus->id : 0; 758 event.key.windowID = keyboard->focus ? keyboard->focus->id : 0;