Fix keyboard input when certain keys overlap with dead keys

This commit is contained in:
Hanicef 2024-05-12 19:44:37 +02:00
parent 488e6d5699
commit 911a351eb4
6 changed files with 65 additions and 13 deletions

View file

@ -922,8 +922,6 @@ static void CON_InputDelChar(void)
//
boolean CON_Responder(event_t *ev)
{
static UINT8 consdown = false; // console is treated differently due to rare usage
// sequential completions a la 4dos
static char completioncmd[80 + sizeof("find ")] = "find ";
static char *completion = &completioncmd[sizeof("find ")-1];
@ -943,32 +941,28 @@ boolean CON_Responder(event_t *ev)
// let go keyup events, don't eat them
if (ev->type != ev_keydown && ev->type != ev_text && ev->type != ev_console)
{
if (ev->key == gamecontrol[GC_CONSOLE][0] || ev->key == gamecontrol[GC_CONSOLE][1])
consdown = false;
return false;
}
key = ev->key;
// check for console toggle key
if (ev->type != ev_console)
if (ev->type == ev_keydown)
{
if (modeattacking || metalrecording || marathonmode)
return false;
if (ev->type == ev_keydown && ((key == gamecontrol[GC_CONSOLE][0] || key == gamecontrol[GC_CONSOLE][1]) && !shiftdown))
if ((key == gamecontrol[GC_CONSOLE][0] || key == gamecontrol[GC_CONSOLE][1]) && !shiftdown)
{
if (consdown) // ignore repeat
return true;
I_SetTextInputMode(con_destlines == 0); // inverse, since this is changed next tic.
consoletoggle = true;
consdown = true;
return true;
}
// check other keys only if console prompt is active
if (!consoleready && key < NUMINPUTS) // metzgermeister: boundary check!!
{
if (ev->type == ev_keydown && !menuactive && bindtable[key])
if (!menuactive && bindtable[key])
{
COM_BufAddText(bindtable[key]);
COM_BufAddText("\n");
@ -980,14 +974,14 @@ boolean CON_Responder(event_t *ev)
// escape key toggle off console
if (key == KEY_ESCAPE)
{
I_SetTextInputMode(false);
consoletoggle = true;
return true;
}
}
if (ev->type == ev_text)
else if (ev->type == ev_text)
{
if (!consoletoggle)
if (!consoletoggle && consoleready)
CON_InputAddChar(key);
return true;
}

View file

@ -999,6 +999,7 @@ static void HU_sendChatMessage(void)
void HU_clearChatChars(void)
{
memset(w_chat, '\0', sizeof(w_chat));
I_SetTextInputMode(false);
chat_on = false;
c_input = 0;
@ -1048,6 +1049,7 @@ boolean HU_Responder(event_t *ev)
if ((ev->key == gamecontrol[GC_TALKKEY][0] || ev->key == gamecontrol[GC_TALKKEY][1])
&& netgame && !OLD_MUTE) // check for old chat mute, still let the players open the chat incase they want to scroll otherwise.
{
I_SetTextInputMode(true);
chat_on = true;
chat_on_first_event = false;
w_chat[0] = 0;
@ -1059,6 +1061,7 @@ boolean HU_Responder(event_t *ev)
if ((ev->key == gamecontrol[GC_TEAMKEY][0] || ev->key == gamecontrol[GC_TEAMKEY][1])
&& netgame && !OLD_MUTE)
{
I_SetTextInputMode(true);
chat_on = true;
chat_on_first_event = false;
w_chat[0] = 0;
@ -1133,6 +1136,7 @@ boolean HU_Responder(event_t *ev)
if (!CHAT_MUTE)
HU_sendChatMessage();
I_SetTextInputMode(false);
chat_on = false;
c_input = 0; // reset input cursor
chat_scrollmedown = true; // you hit enter, so you might wanna autoscroll to see what you just sent. :)
@ -1143,6 +1147,7 @@ boolean HU_Responder(event_t *ev)
|| c == gamecontrol[GC_TEAMKEY][0] || c == gamecontrol[GC_TEAMKEY][1])
&& c >= KEY_MOUSE1)) // If it's not a keyboard key, then the chat button is used as a toggle.
{
I_SetTextInputMode(false);
chat_on = false;
c_input = 0; // reset input cursor
I_UpdateMouseGrab();

View file

@ -339,4 +339,12 @@ void I_SetMouseGrab(boolean grab);
*/
const char *I_GetSysName(void);
/** \brief Sets text input mode. When enabled, keyboard inputs will respect dead keys.
*/
void I_SetTextInputMode(boolean active);
/** \brief Retrieves current text input mode.
*/
boolean I_GetTextInputMode(void);
#endif

View file

@ -2102,6 +2102,12 @@ menu_t OP_PlaystyleDef = {
0, 0, 0, NULL
};
static void M_UpdateItemOn(void)
{
I_SetTextInputMode((currentMenu->menuitems[itemOn].status & IT_CVARTYPE) == IT_CV_STRING ||
(currentMenu->menuitems[itemOn].status & IT_TYPE) == IT_KEYHANDLER);
}
static void M_VideoOptions(INT32 choice)
{
(void)choice;
@ -2329,6 +2335,7 @@ void Nextmap_OnChange(void)
{
currentMenu->lastOn = itemOn;
itemOn = nastart;
M_UpdateItemOn();
}
}
else if (currentMenu == &SP_TimeAttackDef)
@ -2378,6 +2385,7 @@ void Nextmap_OnChange(void)
{
currentMenu->lastOn = itemOn;
itemOn = tastart;
M_UpdateItemOn();
}
if (mapheaderinfo[cv_nextmap.value-1] && mapheaderinfo[cv_nextmap.value-1]->forcecharacter[0] != '\0')
@ -3128,6 +3136,7 @@ static void M_NextOpt(void)
else
itemOn++;
} while (oldItemOn != itemOn && ( (currentMenu->menuitems[itemOn].status & IT_TYPE) & IT_SPACE ));
M_UpdateItemOn();
}
static void M_PrevOpt(void)
@ -3140,6 +3149,7 @@ static void M_PrevOpt(void)
else
itemOn--;
} while (oldItemOn != itemOn && ( (currentMenu->menuitems[itemOn].status & IT_TYPE) & IT_SPACE ));
M_UpdateItemOn();
}
// lock out further input in a tic when important buttons are pressed
@ -3651,12 +3661,14 @@ void M_StartControlPanel(void)
currentMenu = &MainDef;
itemOn = singleplr;
M_UpdateItemOn();
}
else if (modeattacking)
{
currentMenu = &MAPauseDef;
MAPauseMenu[mapause_hints].status = (M_SecretUnlocked(SECRET_EMBLEMHINTS, clientGamedata)) ? (IT_STRING | IT_CALL) : (IT_DISABLED);
itemOn = mapause_continue;
M_UpdateItemOn();
}
else if (!(netgame || multiplayer)) // Single Player
{
@ -3703,6 +3715,7 @@ void M_StartControlPanel(void)
currentMenu = &SPauseDef;
itemOn = spause_continue;
M_UpdateItemOn();
}
else // multiplayer
{
@ -3744,6 +3757,7 @@ void M_StartControlPanel(void)
currentMenu = &MPauseDef;
itemOn = mpause_continue;
M_UpdateItemOn();
}
CON_ToggleOff(); // move away console
@ -3837,6 +3851,7 @@ void M_SetupNextMenu(menu_t *menudef)
}
}
}
M_UpdateItemOn();
hidetitlemap = false;
}
@ -6109,6 +6124,7 @@ void M_StartMessage(const char *string, void *routine, menumessagetype_t itemtyp
currentMenu = &MessageDef;
itemOn = 0;
M_UpdateItemOn();
}
static void M_DrawMessageMenu(void)
@ -6183,6 +6199,7 @@ static void M_HandleImageDef(INT32 choice)
if (itemOn >= (INT16)(currentMenu->numitems-1))
itemOn = 0;
else itemOn++;
M_UpdateItemOn();
break;
case KEY_LEFTARROW:
@ -6193,6 +6210,7 @@ static void M_HandleImageDef(INT32 choice)
if (!itemOn)
itemOn = currentMenu->numitems - 1;
else itemOn--;
M_UpdateItemOn();
break;
case KEY_ESCAPE:
@ -7389,6 +7407,7 @@ static void M_EmblemHints(INT32 choice)
SR_EmblemHintDef.prevMenu = currentMenu;
M_SetupNextMenu(&SR_EmblemHintDef);
itemOn = 2; // always start on back.
M_UpdateItemOn();
}
static void M_DrawEmblemHints(void)
@ -10050,6 +10069,7 @@ static void M_TimeAttack(INT32 choice)
Nextmap_OnChange();
itemOn = tastart; // "Start" is selected.
M_UpdateItemOn();
}
// Drawing function for Nights Attack
@ -10288,6 +10308,7 @@ static void M_NightsAttack(INT32 choice)
Nextmap_OnChange();
itemOn = nastart; // "Start" is selected.
M_UpdateItemOn();
}
// Player has selected the "START" from the nights attack screen
@ -10607,6 +10628,7 @@ static void M_ModeAttackEndGame(INT32 choice)
break;
}
itemOn = currentMenu->lastOn;
M_UpdateItemOn();
G_SetGamestate(GS_TIMEATTACK);
modeattacking = ATTACKING_NONE;
M_ChangeMenuMusic("_title", true);
@ -10688,6 +10710,7 @@ static void M_Marathon(INT32 choice)
titlemapinaction = TITLEMAP_OFF; // Nope don't give us HOMs please
M_SetupNextMenu(&SP_MarathonDef);
itemOn = marathonstart; // "Start" is selected.
M_UpdateItemOn();
recatkdrawtimer = (50-8) * FRACUNIT;
char_scroll = 0;
}
@ -11401,6 +11424,7 @@ static void M_ConnectMenu(INT32 choice)
else
M_SetupNextMenu(&MP_ConnectDef);
itemOn = 0;
M_UpdateItemOn();
M_Refresh(0);
}
@ -11660,6 +11684,7 @@ static void M_StartServerMenu(INT32 choice)
Newgametype_OnChange();
M_SetupNextMenu(&MP_ServerDef);
itemOn = 1;
M_UpdateItemOn();
}
// ==============
@ -13071,7 +13096,10 @@ static void M_SetupScreenshotMenu(void)
{
item->status = IT_GRAYEDOUT;
if ((currentMenu == &OP_ScreenshotOptionsDef) && (itemOn == op_screenshot_colorprofile)) // Can't select that
{
itemOn = op_screenshot_storagelocation;
M_UpdateItemOn();
}
}
else
#endif

View file

@ -186,6 +186,9 @@ int main(int argc, char **argv)
#endif
#endif
// disable text input right off the bat, since we don't need it at the start.
I_SetTextInputMode(false);
#ifdef LOGMESSAGES
if (!M_CheckParm("-nolog"))
InitLogging();

View file

@ -3275,4 +3275,18 @@ const char *I_GetSysName(void)
return SDL_GetPlatform();
}
void I_SetTextInputMode(boolean active)
{
if (active)
SDL_StartTextInput();
else
SDL_StopTextInput();
}
boolean I_GetTextInputMode(void)
{
return SDL_IsTextInputActive();
}
#endif