From bd58d1c1b8c397702741c32d9c58fd6d67414bf9 Mon Sep 17 00:00:00 2001 From: Sander van Dijk Date: Sat, 13 Sep 2014 07:53:31 +0000 Subject: [PATCH] input: Some more console-toggle-key tuning. Partial revert of r1024, since the lastKeyDown stuff is actually needed for SDL2 when the keyboard layout has a printable character that isn't '`' or '~' on the default console-toggle-key (the one below 'Esc'). Instead of hardcoding it though, it is now determined by a new Key_ConsoleBindable function. This makes sure that we don't write an unwanted character into the console as a side effect of opening/closing it, but it still does allow the user to type '`' and '~' in chat messages. git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@1027 af15c1b1-3010-417e-b628-4374ebc0bcbd --- Quake/in_sdl.c | 15 +++++++++++---- Quake/keys.c | 14 +++++++++++++- Quake/keys.h | 1 + 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/Quake/in_sdl.c b/Quake/in_sdl.c index dd10e115..51445ee2 100644 --- a/Quake/in_sdl.c +++ b/Quake/in_sdl.c @@ -496,7 +496,7 @@ void IN_SendKeyEvents (void) SDL_Event event; int sym; #if defined(USE_SDL2) - unsigned char *ch; + static int lastKeyDown = 0; #else int state, modstate; #endif @@ -527,9 +527,11 @@ void IN_SendKeyEvents (void) // 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. - for (ch = (unsigned char *)event.text.text; ch[0] != 0 && ch[0] < 128; ch++) + if (!Key_ConsoleBindable(lastKeyDown)) { - Char_Event (ch[0]); + unsigned char *ch; + for (ch = (unsigned char *)event.text.text; ch[0] != 0 && ch[0] < 128; ch++) + Char_Event (ch[0]); } break; #endif @@ -553,6 +555,11 @@ void IN_SendKeyEvents (void) // layout, so keybindings are based on key position, not the label // on the key cap. sym = IN_SDL2_ScancodeToQuakeKey(event.key.keysym.scancode); + + if (event.type == SDL_KEYDOWN) + lastKeyDown = sym; + else + lastKeyDown = 0; Key_Event (sym, event.key.state == SDL_PRESSED); break; @@ -783,7 +790,7 @@ void IN_SendKeyEvents (void) break; } Key_Event (sym, state); - if (event.type == SDL_KEYDOWN) + if (event.type == SDL_KEYDOWN && !Key_ConsoleBindable(sym)) Char_Event (sym); break; #endif diff --git a/Quake/keys.c b/Quake/keys.c index 9d4230bc..d50e13a2 100644 --- a/Quake/keys.c +++ b/Quake/keys.c @@ -444,7 +444,7 @@ void Char_Console (int key) return; // non printable if (!consolekeys[key]) - return; // bindable key + return; // bindable if (keydown[K_CTRL]) return; // control character @@ -1117,3 +1117,15 @@ void Key_UpdateForDest (void) IN_UpdateForKeydest (); } +/* +=================== +Key_ConsoleBindable +=================== +*/ +qboolean Key_ConsoleBindable(int key) +{ + if ((key_dest == key_console && !consolekeys[key]) || + (key_dest == key_game && con_forcedup && !consolekeys[key])) + return true; + return false; +} diff --git a/Quake/keys.h b/Quake/keys.h index bddc83c6..36da39db 100644 --- a/Quake/keys.h +++ b/Quake/keys.h @@ -163,6 +163,7 @@ extern qboolean chat_team; void Key_Init (void); void Key_ClearStates (void); void Key_UpdateForDest (void); +qboolean Key_ConsoleBindable (int key); void Key_Event (int key, qboolean down); void Char_Event (int key);