diff --git a/src/client/cl_keyboard.c b/src/client/cl_keyboard.c index 6fde0d59..f1def4a1 100644 --- a/src/client/cl_keyboard.c +++ b/src/client/cl_keyboard.c @@ -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; diff --git a/src/client/header/keyboard.h b/src/client/header/keyboard.h index 95a766e4..24870135 100644 --- a/src/client/header/keyboard.h +++ b/src/client/header/keyboard.h @@ -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 }; diff --git a/src/client/input/sdl.c b/src/client/input/sdl.c index d750d197..1f6f00fd 100644 --- a/src/client/input/sdl.c +++ b/src/client/input/sdl.c @@ -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,10 +503,15 @@ IN_Update(void) break; case SDL_TEXTINPUT: - if ((event.text.text[0] >= ' ') && (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(event.text.text[0]); + 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); }