mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-26 22:40:50 +00:00
Introduce K_CONSOLE, generated by the keyboard's "console key"
regardless of keyboard layout, with a special exemption for layouts where that key generates a quote character (like the Brazilian one) because you may wanna type a quote into the console. (It's SDL_SCANCODE_GRAVE, that key between Esc, 1 and Tab) The old hack of matching for ^, ~ and ` in Char_Event() didn't work very well for layouts we didn't anticipate, which is especially relevant with the recent Scancode fallback, which for example allows binding the ^ key on Belgian keyboards (which is on SDL_SCANCODE_LEFTBRACKET, far away from the "console key"), but in that case would *also* open the console. This is mostly straight-forward, except for a small hack to prevent the key from generating text input (on German layouts you otherwise get "^" in the console when closing+opening it), which requires the "console key" to be pressed without any modifiers like Shift or AltGr. Yes, it's ugly, but it works and all the uglyness is contained in IN_Update() and on the other hand Char_Event() becomes less ugly :)
This commit is contained in:
parent
f1a81a5611
commit
a44225c625
3 changed files with 35 additions and 13 deletions
|
@ -1091,13 +1091,6 @@ Key_Init(void)
|
|||
void
|
||||
Char_Event(int key)
|
||||
{
|
||||
/* console key is hardcoded, so the user can never unbind it */
|
||||
if ((key == '^') || (key == '~') || (key == '`'))
|
||||
{
|
||||
Con_ToggleConsole_f();
|
||||
return;
|
||||
}
|
||||
|
||||
switch (cls.key_dest)
|
||||
{
|
||||
/* Chat */
|
||||
|
@ -1202,8 +1195,8 @@ Key_Event(int key, qboolean down, qboolean special)
|
|||
return;
|
||||
}
|
||||
|
||||
/* Toogle console though Shift + Escape */
|
||||
if (down && keydown[K_SHIFT] && key == K_ESCAPE)
|
||||
/* Toogle console through Shift + Escape or special K_CONSOLE key */
|
||||
if ( down && ( key == K_CONSOLE || (keydown[K_SHIFT] && key == K_ESCAPE) ) )
|
||||
{
|
||||
Con_ToggleConsole_f();
|
||||
return;
|
||||
|
|
|
@ -265,7 +265,7 @@ enum QKEYS {
|
|||
K_SC_NONUSHASH,
|
||||
K_SC_SEMICOLON,
|
||||
K_SC_APOSTROPHE,
|
||||
K_SC_GRAVE, // console key
|
||||
K_SC_GRAVE,
|
||||
K_SC_COMMA,
|
||||
K_SC_PERIOD,
|
||||
K_SC_SLASH,
|
||||
|
@ -285,6 +285,12 @@ enum QKEYS {
|
|||
K_SC_CURRENCYUNIT,
|
||||
K_SC_CURRENCYSUBUNIT,
|
||||
|
||||
// hardcoded pseudo-key to open the console, emitted when pressing the "console key"
|
||||
// (SDL_SCANCODE_GRAVE, the one between Esc, 1 and Tab) on layouts that don't
|
||||
// have a relevant char there (unlike Brazilian which has quotes there which you
|
||||
// want to be able to type in the console) - the user can't bind this key.
|
||||
K_CONSOLE,
|
||||
|
||||
K_LAST
|
||||
};
|
||||
|
||||
|
|
|
@ -455,6 +455,8 @@ IN_Update(void)
|
|||
static qboolean left_trigger = false;
|
||||
static qboolean right_trigger = false;
|
||||
|
||||
static int consoleKeyCode = 0;
|
||||
|
||||
/* Get and process an event */
|
||||
while (SDL_PollEvent(&event))
|
||||
{
|
||||
|
@ -501,9 +503,14 @@ IN_Update(void)
|
|||
break;
|
||||
|
||||
case SDL_TEXTINPUT:
|
||||
if ((event.text.text[0] >= ' ') && (event.text.text[0] <= '~'))
|
||||
{
|
||||
Char_Event(event.text.text[0]);
|
||||
int c = event.text.text[0];
|
||||
// also make sure we don't get the char that corresponds to the
|
||||
// "console key" (like "^" or "`") as text input
|
||||
if ((c >= ' ') && (c <= '~') && c != consoleKeyCode)
|
||||
{
|
||||
Char_Event(c);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -535,7 +542,23 @@ IN_Update(void)
|
|||
else
|
||||
{
|
||||
SDL_Keycode kc = event.key.keysym.sym;
|
||||
if ((kc >= SDLK_SPACE) && (kc < SDLK_DELETE))
|
||||
if(sc == SDL_SCANCODE_GRAVE && kc != '\'' && kc != '"')
|
||||
{
|
||||
// special case/hack: open the console with the "console key"
|
||||
// (beneath Esc, left of 1, above Tab)
|
||||
// but not if the keycode for this is a quote (like on Brazilian
|
||||
// keyboards) - otherwise you couldn't type them in the console
|
||||
if((event.key.keysym.mod & (KMOD_CAPS|KMOD_SHIFT|KMOD_ALT|KMOD_CTRL|KMOD_GUI)) == 0)
|
||||
{
|
||||
// also, only do this if no modifiers like shift or AltGr or whatever are pressed
|
||||
// so kc will most likely be the ascii char generated by this and can be ignored
|
||||
// in case SDL_TEXTINPUT above (so we don't get ^ or whatever as text in console)
|
||||
// (can't just check for mod == 0 because numlock is a KMOD too)
|
||||
Key_Event(K_CONSOLE, down, true);
|
||||
consoleKeyCode = kc;
|
||||
}
|
||||
}
|
||||
else if ((kc >= SDLK_SPACE) && (kc < SDLK_DELETE))
|
||||
{
|
||||
Key_Event(kc, down, false);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue