Mercurial > sdl-ios-xcode
comparison test/testwm.c @ 3634:1e31a24c41a6
Merged r4874:4875 from branches/SDL-1.2: testwm keyboard debug output.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Sun, 10 Jan 2010 18:25:04 +0000 |
parents | 6d91cff0ec79 |
children | c127755eebee |
comparison
equal
deleted
inserted
replaced
3633:81dde1b00bf1 | 3634:1e31a24c41a6 |
---|---|
173 printf("Posting internal quit request\n"); | 173 printf("Posting internal quit request\n"); |
174 event.type = SDL_USEREVENT; | 174 event.type = SDL_USEREVENT; |
175 SDL_PushEvent(&event); | 175 SDL_PushEvent(&event); |
176 } | 176 } |
177 | 177 |
178 | |
179 static void | |
180 print_modifiers(void) | |
181 { | |
182 int mod; | |
183 printf(" modifiers:"); | |
184 mod = SDL_GetModState(); | |
185 if(!mod) { | |
186 printf(" (none)"); | |
187 return; | |
188 } | |
189 if(mod & KMOD_LSHIFT) | |
190 printf(" LSHIFT"); | |
191 if(mod & KMOD_RSHIFT) | |
192 printf(" RSHIFT"); | |
193 if(mod & KMOD_LCTRL) | |
194 printf(" LCTRL"); | |
195 if(mod & KMOD_RCTRL) | |
196 printf(" RCTRL"); | |
197 if(mod & KMOD_LALT) | |
198 printf(" LALT"); | |
199 if(mod & KMOD_RALT) | |
200 printf(" RALT"); | |
201 if(mod & KMOD_LMETA) | |
202 printf(" LMETA"); | |
203 if(mod & KMOD_RMETA) | |
204 printf(" RMETA"); | |
205 if(mod & KMOD_NUM) | |
206 printf(" NUM"); | |
207 if(mod & KMOD_CAPS) | |
208 printf(" CAPS"); | |
209 if(mod & KMOD_MODE) | |
210 printf(" MODE"); | |
211 } | |
212 | |
213 static void PrintKey(const SDL_keysym *sym, int pressed) | |
214 { | |
215 /* Print the keycode, name and state */ | |
216 if ( sym->sym ) { | |
217 printf("Key %s: %d-%s ", pressed ? "pressed" : "released", | |
218 sym->sym, SDL_GetKeyName(sym->sym)); | |
219 } else { | |
220 printf("Unknown Key (scancode = %d) %s ", sym->scancode, | |
221 pressed ? "pressed" : "released"); | |
222 } | |
223 | |
224 /* Print the translated character, if one exists */ | |
225 if ( sym->unicode ) { | |
226 /* Is it a control-character? */ | |
227 if ( sym->unicode < ' ' ) { | |
228 printf(" (^%c)", sym->unicode+'@'); | |
229 } else { | |
230 #ifdef UNICODE | |
231 printf(" (%c)", sym->unicode); | |
232 #else | |
233 /* This is a Latin-1 program, so only show 8-bits */ | |
234 if ( !(sym->unicode & 0xFF00) ) | |
235 printf(" (%c)", sym->unicode); | |
236 else | |
237 printf(" (0x%X)", sym->unicode); | |
238 #endif | |
239 } | |
240 } | |
241 print_modifiers(); | |
242 printf("\n"); | |
243 } | |
244 | |
245 | |
178 static int (SDLCALL * old_filterfunc) (void *, SDL_Event *); | 246 static int (SDLCALL * old_filterfunc) (void *, SDL_Event *); |
179 static void *old_filterdata; | 247 static void *old_filterdata; |
180 | 248 |
181 int SDLCALL | 249 int SDLCALL |
182 FilterEvents(void *userdata, SDL_Event * event) | 250 FilterEvents(void *userdata, SDL_Event * event) |
228 event->motion.xrel, event->motion.yrel); | 296 event->motion.xrel, event->motion.yrel); |
229 #endif | 297 #endif |
230 return (0); | 298 return (0); |
231 | 299 |
232 case SDL_KEYDOWN: | 300 case SDL_KEYDOWN: |
301 PrintKey(&event->key.keysym, 1); | |
233 if (event->key.keysym.sym == SDLK_ESCAPE) { | 302 if (event->key.keysym.sym == SDLK_ESCAPE) { |
234 HotKey_Quit(); | 303 HotKey_Quit(); |
235 } | 304 } |
236 if ((event->key.keysym.sym == SDLK_g) && | 305 if ((event->key.keysym.sym == SDLK_g) && |
237 (event->key.keysym.mod & KMOD_CTRL)) { | 306 (event->key.keysym.mod & KMOD_CTRL)) { |
244 if ((event->key.keysym.sym == SDLK_RETURN) && | 313 if ((event->key.keysym.sym == SDLK_RETURN) && |
245 (event->key.keysym.mod & KMOD_ALT)) { | 314 (event->key.keysym.mod & KMOD_ALT)) { |
246 HotKey_ToggleFullScreen(); | 315 HotKey_ToggleFullScreen(); |
247 } | 316 } |
248 return (0); | 317 return (0); |
318 | |
319 case SDL_KEYUP: | |
320 PrintKey(&event->key.keysym, 0); | |
321 return(0); | |
249 | 322 |
250 /* Pass the video resize event through .. */ | 323 /* Pass the video resize event through .. */ |
251 case SDL_VIDEORESIZE: | 324 case SDL_VIDEORESIZE: |
252 return (1); | 325 return (1); |
253 | 326 |
353 | 426 |
354 /* Set an event filter that discards everything but QUIT */ | 427 /* Set an event filter that discards everything but QUIT */ |
355 SDL_GetEventFilter(&old_filterfunc, &old_filterdata); | 428 SDL_GetEventFilter(&old_filterfunc, &old_filterdata); |
356 SDL_SetEventFilter(FilterEvents, NULL); | 429 SDL_SetEventFilter(FilterEvents, NULL); |
357 | 430 |
358 /* Ignore key up events, they don't even get filtered */ | |
359 SDL_EventState(SDL_KEYUP, SDL_IGNORE); | |
360 | |
361 /* Loop, waiting for QUIT */ | 431 /* Loop, waiting for QUIT */ |
362 while (SDL_WaitEvent(&event)) { | 432 while (SDL_WaitEvent(&event)) { |
363 switch (event.type) { | 433 switch (event.type) { |
364 case SDL_VIDEORESIZE: | 434 case SDL_VIDEORESIZE: |
365 printf("Got a resize event: %dx%d\n", | 435 printf("Got a resize event: %dx%d\n", |