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.
Menu fields now mirror behaviour of the console field.
Removed keypad left arrow case from console key ignore list.
This commit is contained in:
apartfromtime 2023-12-12 14:29:52 +11:00
parent 4967b9d0ca
commit 2180ca6c40
3 changed files with 78 additions and 87 deletions

View File

@ -360,7 +360,6 @@ Key_Console(int key)
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:

View File

@ -664,19 +664,41 @@ IN_Update(void)
else
{
int key = IN_TranslateSDLtoQ2Key(kc);
if(key == 0)
if (key == 0)
{
// fallback to scancodes if we don't know the keycode
key = IN_TranslateScancodeToQ2Key(sc);
}
if(key != 0)
{
Key_Event(key, down, true);
}
else
{
Com_DPrintf("Pressed unknown key with SDL_Keycode %d, SDL_Scancode %d.\n", kc, (int)sc);
}
// normal character events
if ((event.key.keysym.mod & KMOD_NUM) == KMOD_NUM)
{
switch (key)
{
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:
key = 0;
break;
}
}
if (key != 0)
{
Key_Event(key, down, true);
}
else
{
Com_DPrintf("Pressed unknown key with SDL_Keycode %d, SDL_Scancode %d.\n", kc, (int)sc);
}
}
}

View File

@ -223,109 +223,79 @@ extern int keydown[];
qboolean
Field_Key(menufield_s *f, int key)
{
/*
* 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:
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;
}
if (key > 127)
{
return false;
}
if ((key == K_BACKSPACE) || (key == K_LEFTARROW) || (key == K_KP_LEFTARROW))
{
if (f->cursor > 0)
{
memmove(&f->buffer[f->cursor - 1], &f->buffer[f->cursor],
strlen(&f->buffer[f->cursor]) + 1);
f->cursor--;
switch (key)
{
case K_KP_LEFTARROW:
case K_LEFTARROW:
case K_BACKSPACE:
if (f->visible_offset)
{
f->visible_offset--;
}
}
if (f->cursor > 0)
{
memmove(&f->buffer[f->cursor - 1],
&f->buffer[f->cursor],
strlen(&f->buffer[f->cursor]) + 1);
f->cursor--;
return true;
}
if (f->visible_offset)
{
f->visible_offset--;
}
}
if ((key == K_DEL) || (key == K_KP_DEL))
{
memmove(&f->buffer[f->cursor], &f->buffer[f->cursor + 1],
strlen(&f->buffer[f->cursor + 1]) + 1);
return true;
}
break;
if (key == K_ENTER || key == K_KP_ENTER || key == K_ESCAPE || key == K_TAB)
{
return false;
}
case K_KP_DEL:
case K_DEL:
memmove(&f->buffer[f->cursor], &f->buffer[f->cursor + 1],
strlen(&f->buffer[f->cursor + 1]) + 1);
break;
if ((key < 32) || (key > 127))
{
return false; /* non printable character */
}
case K_KP_ENTER:
case K_ENTER:
case K_ESCAPE:
case K_TAB:
return false;
if (!isdigit(key) && (f->generic.flags & QMF_NUMBERSONLY))
{
return false;
}
case K_SPACE:
default:
if (f->cursor < f->length)
{
f->buffer[f->cursor++] = key;
f->buffer[f->cursor] = 0;
if (!isdigit(key) && (f->generic.flags & QMF_NUMBERSONLY))
{
return false;
}
if (f->cursor < f->length)
{
f->buffer[f->cursor++] = key;
f->buffer[f->cursor] = 0;
if (f->cursor > f->visible_length)
{
f->visible_offset++;
}
}
}
if (f->cursor > f->visible_length)
{
f->visible_offset++;
}
}
return true;
}