comparison test/checkkeys.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 95586dfe1992
children 25d4feb7c127
comparison
equal deleted inserted replaced
4559:f8c3870af5a2 4560:95352c671a6e
51 if (mod & KMOD_MODE) 51 if (mod & KMOD_MODE)
52 printf(" MODE"); 52 printf(" MODE");
53 } 53 }
54 54
55 static void 55 static void
56 PrintKey(SDL_keysym * sym, int pressed) 56 PrintKey(SDL_keysym * sym, SDL_bool pressed, SDL_bool repeat)
57 { 57 {
58 /* Print the keycode, name and state */ 58 /* Print the keycode, name and state */
59 if (sym->sym) { 59 if (sym->sym) {
60 printf("Key %s: scancode %d = %s, keycode 0x%08X = %s ", 60 printf("Key %s: scancode %d = %s, keycode 0x%08X = %s ",
61 pressed ? "pressed " : "released", 61 pressed ? "pressed " : "released",
85 printf(" (0x%X)", sym->unicode); 85 printf(" (0x%X)", sym->unicode);
86 #endif 86 #endif
87 } 87 }
88 } 88 }
89 print_modifiers(); 89 print_modifiers();
90 if (repeat) {
91 printf(" (repeat)");
92 }
90 printf("\n"); 93 printf("\n");
91 } 94 }
92 95
93 static void 96 static void
94 PrintText(char *text) 97 PrintText(char *text)
132 while (!done) { 135 while (!done) {
133 /* Check for events */ 136 /* Check for events */
134 SDL_WaitEvent(&event); 137 SDL_WaitEvent(&event);
135 switch (event.type) { 138 switch (event.type) {
136 case SDL_KEYDOWN: 139 case SDL_KEYDOWN:
137 PrintKey(&event.key.keysym, 1);
138 break;
139 case SDL_KEYUP: 140 case SDL_KEYUP:
140 PrintKey(&event.key.keysym, 0); 141 PrintKey(&event.key.keysym, event.key.state, event.key.repeat);
141 break; 142 break;
142 case SDL_TEXTINPUT: 143 case SDL_TEXTINPUT:
143 PrintText(event.text.text); 144 PrintText(event.text.text);
144 break; 145 break;
145 case SDL_MOUSEBUTTONDOWN: 146 case SDL_MOUSEBUTTONDOWN: