Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map SDL_SCANCODE_GRAVE to the console key. #285

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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