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
This commit is contained in:
Sander van Dijk 2014-09-13 07:53:31 +00:00
parent a5e4a93cf0
commit bd58d1c1b8
3 changed files with 25 additions and 5 deletions

View File

@ -496,7 +496,7 @@ void IN_SendKeyEvents (void)
SDL_Event event; SDL_Event event;
int sym; int sym;
#if defined(USE_SDL2) #if defined(USE_SDL2)
unsigned char *ch; static int lastKeyDown = 0;
#else #else
int state, modstate; int state, modstate;
#endif #endif
@ -527,9 +527,11 @@ void IN_SendKeyEvents (void)
// SDL2: We use SDL_TEXTINPUT for typing in the console / chat. // SDL2: We use SDL_TEXTINPUT for typing in the console / chat.
// SDL2 uses the local keyboard layout and handles modifiers // SDL2 uses the local keyboard layout and handles modifiers
// (shift for uppercase, etc.) for us. // (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; break;
#endif #endif
@ -553,6 +555,11 @@ void IN_SendKeyEvents (void)
// layout, so keybindings are based on key position, not the label // layout, so keybindings are based on key position, not the label
// on the key cap. // on the key cap.
sym = IN_SDL2_ScancodeToQuakeKey(event.key.keysym.scancode); 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); Key_Event (sym, event.key.state == SDL_PRESSED);
break; break;
@ -783,7 +790,7 @@ void IN_SendKeyEvents (void)
break; break;
} }
Key_Event (sym, state); Key_Event (sym, state);
if (event.type == SDL_KEYDOWN) if (event.type == SDL_KEYDOWN && !Key_ConsoleBindable(sym))
Char_Event (sym); Char_Event (sym);
break; break;
#endif #endif

View File

@ -444,7 +444,7 @@ void Char_Console (int key)
return; // non printable return; // non printable
if (!consolekeys[key]) if (!consolekeys[key])
return; // bindable key return; // bindable
if (keydown[K_CTRL]) if (keydown[K_CTRL])
return; // control character return; // control character
@ -1117,3 +1117,15 @@ void Key_UpdateForDest (void)
IN_UpdateForKeydest (); 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;
}

View File

@ -163,6 +163,7 @@ extern qboolean chat_team;
void Key_Init (void); void Key_Init (void);
void Key_ClearStates (void); void Key_ClearStates (void);
void Key_UpdateForDest (void); void Key_UpdateForDest (void);
qboolean Key_ConsoleBindable (int key);
void Key_Event (int key, qboolean down); void Key_Event (int key, qboolean down);
void Char_Event (int key); void Char_Event (int key);