Added keyboard output for debugging bug #659 SDL-1.2
authorSam Lantinga <slouken@libsdl.org>
Mon, 28 Sep 2009 07:04:25 +0000
branchSDL-1.2
changeset 425714195cfdb66e
parent 4256 ba587a51f899
child 4258 ca02f877d055
Added keyboard output for debugging bug #659
test/testwm.c
     1.1 --- a/test/testwm.c	Mon Sep 28 06:23:22 2009 +0000
     1.2 +++ b/test/testwm.c	Mon Sep 28 07:04:25 2009 +0000
     1.3 @@ -168,6 +168,71 @@
     1.4  	SDL_PushEvent(&event);
     1.5  }
     1.6  
     1.7 +static void print_modifiers(void)
     1.8 +{
     1.9 +	int mod;
    1.10 +	printf(" modifiers:");
    1.11 +	mod = SDL_GetModState();
    1.12 +	if(!mod) {
    1.13 +		printf(" (none)");
    1.14 +		return;
    1.15 +	}
    1.16 +	if(mod & KMOD_LSHIFT)
    1.17 +		printf(" LSHIFT");
    1.18 +	if(mod & KMOD_RSHIFT)
    1.19 +		printf(" RSHIFT");
    1.20 +	if(mod & KMOD_LCTRL)
    1.21 +		printf(" LCTRL");
    1.22 +	if(mod & KMOD_RCTRL)
    1.23 +		printf(" RCTRL");
    1.24 +	if(mod & KMOD_LALT)
    1.25 +		printf(" LALT");
    1.26 +	if(mod & KMOD_RALT)
    1.27 +		printf(" RALT");
    1.28 +	if(mod & KMOD_LMETA)
    1.29 +		printf(" LMETA");
    1.30 +	if(mod & KMOD_RMETA)
    1.31 +		printf(" RMETA");
    1.32 +	if(mod & KMOD_NUM)
    1.33 +		printf(" NUM");
    1.34 +	if(mod & KMOD_CAPS)
    1.35 +		printf(" CAPS");
    1.36 +	if(mod & KMOD_MODE)
    1.37 +		printf(" MODE");
    1.38 +}
    1.39 +
    1.40 +static void PrintKey(const SDL_keysym *sym, int pressed)
    1.41 +{
    1.42 +	/* Print the keycode, name and state */
    1.43 +	if ( sym->sym ) {
    1.44 +		printf("Key %s:  %d-%s ", pressed ?  "pressed" : "released",
    1.45 +					sym->sym, SDL_GetKeyName(sym->sym));
    1.46 +	} else {
    1.47 +		printf("Unknown Key (scancode = %d) %s ", sym->scancode,
    1.48 +					pressed ?  "pressed" : "released");
    1.49 +	}
    1.50 +
    1.51 +	/* Print the translated character, if one exists */
    1.52 +	if ( sym->unicode ) {
    1.53 +		/* Is it a control-character? */
    1.54 +		if ( sym->unicode < ' ' ) {
    1.55 +			printf(" (^%c)", sym->unicode+'@');
    1.56 +		} else {
    1.57 +#ifdef UNICODE
    1.58 +			printf(" (%c)", sym->unicode);
    1.59 +#else
    1.60 +			/* This is a Latin-1 program, so only show 8-bits */
    1.61 +			if ( !(sym->unicode & 0xFF00) )
    1.62 +				printf(" (%c)", sym->unicode);
    1.63 +			else
    1.64 +				printf(" (0x%X)", sym->unicode);
    1.65 +#endif
    1.66 +		}
    1.67 +	}
    1.68 +	print_modifiers();
    1.69 +	printf("\n");
    1.70 +}
    1.71 +
    1.72  int SDLCALL FilterEvents(const SDL_Event *event)
    1.73  {
    1.74  	static int reallyquit = 0;
    1.75 @@ -217,6 +282,7 @@
    1.76  			return(0);
    1.77  
    1.78  		case SDL_KEYDOWN:
    1.79 +			PrintKey(&event->key.keysym, 1);
    1.80  			if ( event->key.keysym.sym == SDLK_ESCAPE ) {
    1.81  				HotKey_Quit();
    1.82  			}
    1.83 @@ -234,6 +300,10 @@
    1.84  			}
    1.85  			return(0);
    1.86  
    1.87 +		case SDL_KEYUP:
    1.88 +			PrintKey(&event->key.keysym, 0);
    1.89 +			return(0);
    1.90 +
    1.91  		/* Pass the video resize event through .. */
    1.92  		case SDL_VIDEORESIZE:
    1.93  			return(1);
    1.94 @@ -346,9 +416,6 @@
    1.95  	/* Set an event filter that discards everything but QUIT */
    1.96  	SDL_SetEventFilter(FilterEvents);
    1.97  
    1.98 -	/* Ignore key up events, they don't even get filtered */
    1.99 -	SDL_EventState(SDL_KEYUP, SDL_IGNORE);
   1.100 -
   1.101  	/* Loop, waiting for QUIT */
   1.102  	while ( SDL_WaitEvent(&event) ) {
   1.103  		switch (event.type) {