From f607f1b4eb10b2c9e30470b3a6f13073bfb88551 Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Tue, 14 Oct 2014 18:31:49 +0000 Subject: [PATCH] in_sdl: change DBEUG_INPUT preprocessor check to an "in_debugkeys" cvar to make it easier to debug unusual keyboards git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@1114 af15c1b1-3010-417e-b628-4374ebc0bcbd --- Quake/in_sdl.c | 47 +++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/Quake/in_sdl.c b/Quake/in_sdl.c index 7d172f74..752f7a53 100644 --- a/Quake/in_sdl.c +++ b/Quake/in_sdl.c @@ -34,6 +34,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static qboolean textmode; +static cvar_t in_debugkeys = {"in_debugkeys", "0", CVAR_NONE}; + #ifdef __APPLE__ /* Mouse acceleration needs to be disabled on OS X */ #define MACOS_X_ACCELERATION_HACK @@ -279,6 +281,7 @@ void IN_Init (void) #ifdef MACOS_X_ACCELERATION_HACK Cvar_RegisterVariable(&in_disablemacosxmouseaccel); #endif + Cvar_RegisterVariable(&in_debugkeys); IN_Activate(); } @@ -562,6 +565,29 @@ static inline int IN_SDL2_ScancodeToQuakeKey(SDL_Scancode scancode) } #endif +#if defined(USE_SDL2) +static void IN_DebugTextEvent(SDL_Event *event) +{ + Con_Printf ("SDL_TEXTINPUT '%s'\n", event->text.text); +} +#endif + +static void IN_DebugKeyEvent(SDL_Event *event) +{ + const char *eventtype = (event->key.state == SDL_PRESSED) ? "SDL_KEYDOWN" : "SDL_KEYUP"; +#if defined(USE_SDL2) + Con_Printf ("%s scancode: '%s' keycode: '%s'\n", + eventtype, + SDL_GetScancodeName(event->key.keysym.scancode), + SDL_GetKeyName(event->key.keysym.sym)); +#else + Con_Printf ("%s sym: '%s' unicode: %04x\n", + eventtype, + SDL_GetKeyName(event->key.keysym.sym), + (int)event->key.keysym.unicode); +#endif +} + void IN_SendKeyEvents (void) { SDL_Event event; @@ -591,9 +617,9 @@ void IN_SendKeyEvents (void) #endif #if defined(USE_SDL2) case SDL_TEXTINPUT: -#if defined(DEBUG_INPUT) - printf ("SDL_TEXTINPUT '%s'\n", event.text.text); -#endif + if (in_debugkeys.value) + IN_DebugTextEvent(&event); + // SDL2: We use SDL_TEXTINPUT for typing in the console / chat. // SDL2 uses the local keyboard layout and handles modifiers // (shift for uppercase, etc.) for us. @@ -609,19 +635,8 @@ void IN_SendKeyEvents (void) case SDL_KEYUP: down = (event.key.state == SDL_PRESSED); -#if defined(DEBUG_INPUT) -#if defined(USE_SDL2) - printf ("%s scancode: '%s' keycode: '%s'\n", - down ? "SDL_KEYDOWN" : "SDL_KEYUP", - SDL_GetScancodeName(event.key.keysym.scancode), - SDL_GetKeyName(event.key.keysym.sym)); -#else - printf ("%s sym: '%s' unicode: %04x\n", - down ? "SDL_KEYDOWN" : "SDL_KEYUP", - SDL_GetKeyName(event.key.keysym.sym), - (int)event.key.keysym.unicode); -#endif -#endif + if (in_debugkeys.value) + IN_DebugKeyEvent(&event); #if defined(USE_SDL2) // SDL2: we interpret the keyboard as the US layout, so keybindings