Skip to content

Commit

Permalink
Map SDL_SCANCODE_GRAVE to the console key.
Browse files Browse the repository at this point in the history
Currently, the only way to invoke the console which is both platform and
layout independent is to use Shift+Escape.

This change makes sure the QWERTY '`' key (at the left of the 1 key)
works as a console key and for all keyboard layout by matching against
its scan code (ie physical location).

Since this key can also be mapped to normal characters that could be
useful for text input (eg, '^' on German keyboards), we only interpret
it as a console key if one of those conditions is respected:
 - The resulting key is valid and outside ascii range (0x20-0x7f)
 - The resulting key is '~' or '`'
 - The console input field is empty and no chat message is being written

Additionaly, no modifiers (Shift, Ctrl, Alt, AltGr, Ctrl, Super/Win)
shall be pressed to allow usage of the keys in the Shift/AltGr group and
to allow bypassing the console (Alt works on X11, Windows key must be used
on Windows)

A new `cl_consoleUseScanCode` cvar (default 1) is added to enable the
feature.
  • Loading branch information
mickael9 committed Apr 6, 2017
1 parent d7a99d5 commit a455e98
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions code/client/cl_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ cvar_t *cl_lanForcePackets;
cvar_t *cl_guidServerUniq;

cvar_t *cl_consoleKeys;
cvar_t *cl_consoleUseScanCode;

cvar_t *cl_rate;

Expand Down Expand Up @@ -3607,6 +3608,7 @@ void CL_Init( void ) {

// ~ and `, as keys and characters
cl_consoleKeys = Cvar_Get( "cl_consoleKeys", "~ ` 0x7e 0x60", CVAR_ARCHIVE);
cl_consoleUseScanCode = Cvar_Get( "cl_consoleUseScanCode", "1", CVAR_ARCHIVE);

// userinfo
Cvar_Get ("name", "UnnamedPlayer", CVAR_USERINFO | CVAR_ARCHIVE );
Expand Down
1 change: 1 addition & 0 deletions code/client/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ extern cvar_t *cl_lanForcePackets;
extern cvar_t *cl_autoRecordDemo;

extern cvar_t *cl_consoleKeys;
extern cvar_t *cl_consoleUseScanCode;

#ifdef USE_MUMBLE
extern cvar_t *cl_useMumble;
Expand Down
26 changes: 26 additions & 0 deletions code/sdl/sdl_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,32 @@ static keyNum_t IN_TranslateSDLToQ3Key( SDL_Keysym *keysym, qboolean down )
{
// Console keys can't be bound or generate characters
key = K_CONSOLE;
} else if ( cl_consoleUseScanCode->integer && keysym->scancode == SDL_SCANCODE_GRAVE ) {
// Use the QWERTY grave key location as a console key (whatever the actual layout)
// We try our best to avoid any possible conflicts with keys at this location
// on other layouts such as:
// ^ (German)
// " (Brazilian)
// $ (French Bepo, Programmer Dvorak)
// 0 (Hungarian)
// ; (Czech)
// | (Italian)
// # (Canadian French)
// and probably others
qboolean console_has_text = strlen(g_consoleField.buffer) > 0;

// Don't force console if a modifier is held
if ( keys[K_SHIFT].down || keys[K_ALT].down || keys[K_CTRL].down || keys[K_SUPER].down ) {
return key;
}

// We need to exclude the invalid 0 key because the German layout outputs a dead key
// which is not recognized correctly by SDL under X11
if ( (key > 0 && key < 0x20) || key > 0x7f || key == '~' || key == '`'
|| ( Key_GetCatcher() != KEYCATCH_MESSAGE && !console_has_text ) )
{
key = K_CONSOLE;
}
}

return key;
Expand Down

0 comments on commit a455e98

Please sign in to comment.