diff --git a/Quake/in_sdl.c b/Quake/in_sdl.c index f538038e..60587ca9 100644 --- a/Quake/in_sdl.c +++ b/Quake/in_sdl.c @@ -370,6 +370,12 @@ void IN_UpdateForKeydest (void) } #if defined(USE_SDL2) + +static qboolean IN_SDL2_QuakeKeyHandledAsTextInput(int qkey) +{ + return (qkey >= 32 && qkey <= 126) && qkey != '`'; +} + static inline int IN_SDL2_ScancodeToQuakeKey(SDL_Scancode scancode) { switch (scancode) @@ -517,7 +523,23 @@ void IN_SendKeyEvents (void) else S_BlockSound(); } break; - +#endif +#if defined(USE_SDL2) + case SDL_TEXTINPUT: + { + char *ch; + for (ch = event.text.text; *ch != '\0'; ch++) + { + int qkey = *ch; + + if (IN_SDL2_QuakeKeyHandledAsTextInput(qkey) && !gamekey) + { + Key_Event (qkey, SDL_PRESSED, false); + Key_Event (qkey, SDL_RELEASED, false); + } + } + } + break; #endif case SDL_KEYDOWN: if ((event.key.keysym.sym == SDLK_RETURN) && @@ -536,10 +558,14 @@ void IN_SendKeyEvents (void) case SDL_KEYUP: #if defined(USE_SDL2) sym = IN_SDL2_ScancodeToQuakeKey(event.key.keysym.scancode); - state = event.key.state; - modstate = SDL_GetModState(); - - Key_Event (sym, state); + + if (gamekey || !IN_SDL2_QuakeKeyHandledAsTextInput(sym)) + { + state = event.key.state; + + Key_Event (sym, state, true); + } + break; #else sym = event.key.keysym.sym; state = event.key.state; @@ -766,10 +792,9 @@ void IN_SendKeyEvents (void) sym = 0; break; } - Key_Event (sym, state); -#endif + Key_Event (sym, state, true); break; - +#endif case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: if (event.button.button < 1 || @@ -779,20 +804,20 @@ void IN_SendKeyEvents (void) event.button.button); break; } - Key_Event(buttonremap[event.button.button - 1], event.button.state == SDL_PRESSED); + Key_Event(buttonremap[event.button.button - 1], event.button.state == SDL_PRESSED, true); break; #if defined(USE_SDL2) case SDL_MOUSEWHEEL: if (event.wheel.y > 0) { - Key_Event(K_MWHEELUP, false); - Key_Event(K_MWHEELUP, true); + Key_Event(K_MWHEELUP, false, true); + Key_Event(K_MWHEELUP, true, true); } else if (event.wheel.y < 0) { - Key_Event(K_MWHEELDOWN, false); - Key_Event(K_MWHEELDOWN, true); + Key_Event(K_MWHEELDOWN, false, true); + Key_Event(K_MWHEELDOWN, true, true); } break; #endif diff --git a/Quake/keys.c b/Quake/keys.c index 7c580afe..883e8ce5 100644 --- a/Quake/keys.c +++ b/Quake/keys.c @@ -888,9 +888,12 @@ Key_Event Called by the system between frames for both key up and key down events Should NOT be called during an interrupt! + +If interpret_shift is true, and the shift key is currently down, handles +mapping to the shifted version of a key. e.g. '5' -> '%' =================== */ -void Key_Event (int key, qboolean down) +void Key_Event (int key, qboolean down, qboolean interpret_shift) { char *kb; char cmd[1024]; @@ -1001,7 +1004,7 @@ void Key_Event (int key, qboolean down) if (!down) return; // other systems only care about key down events - if (shift_down) + if (shift_down && interpret_shift) key = keyshift[key]; switch (key_dest) @@ -1034,7 +1037,7 @@ void Key_ClearStates (void) for (i = 0; i < 256; i++) { if (keydown[i]) - Key_Event (i, false); + Key_Event (i, false, true); } } diff --git a/Quake/keys.h b/Quake/keys.h index e3105732..3c7bbe62 100644 --- a/Quake/keys.h +++ b/Quake/keys.h @@ -164,7 +164,7 @@ void Key_Init (void); void Key_ClearStates (void); void Key_UpdateForDest (void); -void Key_Event (int key, qboolean down); +void Key_Event (int key, qboolean down, qboolean interpret_shift); void Key_SetBinding (int keynum, const char *binding); const char *Key_KeynumToString (int keynum);