comparison src/events/SDL_keyboard.c @ 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 05ab4141ce93
children dc9d77a26388
comparison
equal deleted inserted replaced
4559:f8c3870af5a2 4560:95352c671a6e
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); 569 SDL_SendKeyboardKey(SDL_RELEASED, scancode, SDL_FALSE);
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) 630 SDL_SendKeyboardKey(Uint8 state, SDL_scancode scancode, SDL_bool repeat)
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;
730 /* Invalid state -- bail */ 730 /* Invalid state -- bail */
731 return 0; 731 return 0;
732 } 732 }
733 733
734 /* Drop events that don't change state */ 734 /* Drop events that don't change state */
735 if (keyboard->keystate[scancode] == state) { 735 if (keyboard->keystate[scancode] == state && !repeat) {
736 #if 0 736 #if 0
737 printf("Keyboard event didn't change state - dropped!\n"); 737 printf("Keyboard event didn't change state - dropped!\n");
738 #endif 738 #endif
739 return 0; 739 return 0;
740 } 740 }
746 posted = 0; 746 posted = 0;
747 if (SDL_GetEventState(type) == SDL_ENABLE) { 747 if (SDL_GetEventState(type) == SDL_ENABLE) {
748 SDL_Event event; 748 SDL_Event event;
749 event.key.type = type; 749 event.key.type = type;
750 event.key.state = state; 750 event.key.state = state;
751 event.key.repeat = repeat ? 1 : 0;
751 event.key.keysym.scancode = scancode; 752 event.key.keysym.scancode = scancode;
752 event.key.keysym.sym = keyboard->keymap[scancode]; 753 event.key.keysym.sym = keyboard->keymap[scancode];
753 event.key.keysym.mod = modstate; 754 event.key.keysym.mod = modstate;
754 event.key.keysym.unicode = 0; 755 event.key.keysym.unicode = 0;
755 event.key.windowID = keyboard->focus ? keyboard->focus->id : 0; 756 event.key.windowID = keyboard->focus ? keyboard->focus->id : 0;