Fix duplicate menu key keyboard entries

Fixes a bug where duplicate keyboard entries would occur in menu fields when using the keypad keys with num-lock on.

Adds `IN_NumpadIsOn` function returning the state of the numpad key.
This commit is contained in:
apartfromtime 2023-12-17 09:55:58 +11:00
parent ef456964e3
commit 089a1cd53f
4 changed files with 48 additions and 45 deletions

View file

@ -276,6 +276,7 @@ extern int chat_bufferlen;
extern int chat_cursorpos;
extern qboolean chat_team;
qboolean IN_NumpadIsOn();
void Char_Event(int key);
void Key_Event(int key, qboolean down, qboolean special);
void Key_Init(void);

View file

@ -537,6 +537,18 @@ IN_TranslateGamepadBtnToQ2Key(int btn)
static void IN_Controller_Init(qboolean notify_user);
static void IN_Controller_Shutdown(qboolean notify_user);
qboolean IN_NumpadIsOn()
{
SDL_Keymod mod = SDL_GetModState();
if ((mod & KMOD_NUM) == KMOD_NUM)
{
return true;
}
return false;
}
/* ------------------------------------------------------------------ */
/*

View file

@ -242,23 +242,27 @@ Key_GetMenuKey(int key)
switch (key)
{
case K_KP_UPARROW:
if (IN_NumpadIsOn() == true) { break; }
case K_UPARROW:
case K_DPAD_UP:
return K_UPARROW;
case K_TAB:
case K_KP_DOWNARROW:
if (IN_NumpadIsOn() == true) { break; }
case K_DOWNARROW:
case K_DPAD_DOWN:
return K_DOWNARROW;
case K_KP_LEFTARROW:
if (IN_NumpadIsOn() == true) { break; }
case K_LEFTARROW:
case K_DPAD_LEFT:
case K_SHOULDER_LEFT:
return K_LEFTARROW;
case K_KP_RIGHTARROW:
if (IN_NumpadIsOn() == true) { break; }
case K_RIGHTARROW:
case K_DPAD_RIGHT:
case K_SHOULDER_RIGHT:
@ -283,12 +287,18 @@ Key_GetMenuKey(int key)
case K_BACKSPACE:
case K_DEL:
case K_KP_DEL:
if (IN_NumpadIsOn() == true) { break; }
case K_BTN_Y:
return K_BACKSPACE;
case K_KP_INS:
if (IN_NumpadIsOn() == true) { break; }
case K_INS:
return K_INS;
}
return key;
}
const char *
Default_MenuKey(menuframework_s *m, int key)
{

View file

@ -223,51 +223,31 @@ extern int keydown[];
qboolean
Field_Key(menufield_s *f, int key)
{
switch (key)
{
case K_KP_SLASH:
key = '/';
break;
case K_KP_MINUS:
key = '-';
break;
case K_KP_PLUS:
key = '+';
break;
case K_KP_HOME:
key = '7';
break;
case K_KP_UPARROW:
key = '8';
break;
case K_KP_PGUP:
key = '9';
break;
case K_KP_LEFTARROW:
key = '4';
break;
case K_KP_5:
key = '5';
break;
case K_KP_RIGHTARROW:
key = '6';
break;
case K_KP_END:
key = '1';
break;
case K_KP_DOWNARROW:
key = '2';
break;
case K_KP_PGDN:
key = '3';
break;
case K_KP_INS:
key = '0';
break;
case K_KP_DEL:
key = '.';
break;
}
/*
* Ignore keypad in field to prevent duplicate
* entries through key presses processed as a
* normal char event and additionally as key
* event.
*/
switch (key)
{
case K_KP_SLASH:
case K_KP_MINUS:
case K_KP_PLUS:
case K_KP_HOME:
case K_KP_UPARROW:
case K_KP_PGUP:
case K_KP_LEFTARROW:
case K_KP_5:
case K_KP_RIGHTARROW:
case K_KP_END:
case K_KP_DOWNARROW:
case K_KP_PGDN:
case K_KP_INS:
case K_KP_DEL:
default:
break;
}
if (key > 127)
{