mirror of
https://github.com/Shpoike/Quakespasm.git
synced 2025-02-19 02:22:01 +00:00
sdl2: keyboard handling: use text input events for console/chat text entry
This commit is contained in:
parent
2e2360bf0e
commit
af4efc022c
3 changed files with 45 additions and 17 deletions
|
@ -370,6 +370,12 @@ void IN_UpdateForKeydest (void)
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(USE_SDL2)
|
#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)
|
static inline int IN_SDL2_ScancodeToQuakeKey(SDL_Scancode scancode)
|
||||||
{
|
{
|
||||||
switch (scancode)
|
switch (scancode)
|
||||||
|
@ -517,7 +523,23 @@ void IN_SendKeyEvents (void)
|
||||||
else S_BlockSound();
|
else S_BlockSound();
|
||||||
}
|
}
|
||||||
break;
|
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
|
#endif
|
||||||
case SDL_KEYDOWN:
|
case SDL_KEYDOWN:
|
||||||
if ((event.key.keysym.sym == SDLK_RETURN) &&
|
if ((event.key.keysym.sym == SDLK_RETURN) &&
|
||||||
|
@ -536,10 +558,14 @@ void IN_SendKeyEvents (void)
|
||||||
case SDL_KEYUP:
|
case SDL_KEYUP:
|
||||||
#if defined(USE_SDL2)
|
#if defined(USE_SDL2)
|
||||||
sym = IN_SDL2_ScancodeToQuakeKey(event.key.keysym.scancode);
|
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
|
#else
|
||||||
sym = event.key.keysym.sym;
|
sym = event.key.keysym.sym;
|
||||||
state = event.key.state;
|
state = event.key.state;
|
||||||
|
@ -766,10 +792,9 @@ void IN_SendKeyEvents (void)
|
||||||
sym = 0;
|
sym = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Key_Event (sym, state);
|
Key_Event (sym, state, true);
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
case SDL_MOUSEBUTTONDOWN:
|
case SDL_MOUSEBUTTONDOWN:
|
||||||
case SDL_MOUSEBUTTONUP:
|
case SDL_MOUSEBUTTONUP:
|
||||||
if (event.button.button < 1 ||
|
if (event.button.button < 1 ||
|
||||||
|
@ -779,20 +804,20 @@ void IN_SendKeyEvents (void)
|
||||||
event.button.button);
|
event.button.button);
|
||||||
break;
|
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;
|
break;
|
||||||
|
|
||||||
#if defined(USE_SDL2)
|
#if defined(USE_SDL2)
|
||||||
case SDL_MOUSEWHEEL:
|
case SDL_MOUSEWHEEL:
|
||||||
if (event.wheel.y > 0)
|
if (event.wheel.y > 0)
|
||||||
{
|
{
|
||||||
Key_Event(K_MWHEELUP, false);
|
Key_Event(K_MWHEELUP, false, true);
|
||||||
Key_Event(K_MWHEELUP, true);
|
Key_Event(K_MWHEELUP, true, true);
|
||||||
}
|
}
|
||||||
else if (event.wheel.y < 0)
|
else if (event.wheel.y < 0)
|
||||||
{
|
{
|
||||||
Key_Event(K_MWHEELDOWN, false);
|
Key_Event(K_MWHEELDOWN, false, true);
|
||||||
Key_Event(K_MWHEELDOWN, true);
|
Key_Event(K_MWHEELDOWN, true, true);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -888,9 +888,12 @@ Key_Event
|
||||||
|
|
||||||
Called by the system between frames for both key up and key down events
|
Called by the system between frames for both key up and key down events
|
||||||
Should NOT be called during an interrupt!
|
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 *kb;
|
||||||
char cmd[1024];
|
char cmd[1024];
|
||||||
|
@ -1001,7 +1004,7 @@ void Key_Event (int key, qboolean down)
|
||||||
if (!down)
|
if (!down)
|
||||||
return; // other systems only care about key down events
|
return; // other systems only care about key down events
|
||||||
|
|
||||||
if (shift_down)
|
if (shift_down && interpret_shift)
|
||||||
key = keyshift[key];
|
key = keyshift[key];
|
||||||
|
|
||||||
switch (key_dest)
|
switch (key_dest)
|
||||||
|
@ -1034,7 +1037,7 @@ void Key_ClearStates (void)
|
||||||
for (i = 0; i < 256; i++)
|
for (i = 0; i < 256; i++)
|
||||||
{
|
{
|
||||||
if (keydown[i])
|
if (keydown[i])
|
||||||
Key_Event (i, false);
|
Key_Event (i, false, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -164,7 +164,7 @@ void Key_Init (void);
|
||||||
void Key_ClearStates (void);
|
void Key_ClearStates (void);
|
||||||
void Key_UpdateForDest (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);
|
void Key_SetBinding (int keynum, const char *binding);
|
||||||
const char *Key_KeynumToString (int keynum);
|
const char *Key_KeynumToString (int keynum);
|
||||||
|
|
Loading…
Reference in a new issue