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_HOME:
case K_KP_UPARROW: case K_KP_UPARROW:
case K_KP_PGUP: case K_KP_PGUP:
case K_KP_LEFTARROW:
case K_KP_5: case K_KP_5:
case K_KP_RIGHTARROW: case K_KP_RIGHTARROW:
case K_KP_END: case K_KP_END:

View file

@ -669,6 +669,28 @@ IN_Update(void)
// fallback to scancodes if we don't know the keycode // fallback to scancodes if we don't know the keycode
key = IN_TranslateScancodeToQ2Key(sc); key = IN_TranslateScancodeToQ2Key(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) if (key != 0)
{ {
Key_Event(key, down, true); Key_Event(key, down, true);

View file

@ -223,67 +223,35 @@ extern int keydown[];
qboolean qboolean
Field_Key(menufield_s *f, int key) 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) switch (key)
{ {
case K_KP_SLASH: case K_KP_SLASH:
key = '/';
break;
case K_KP_MINUS: case K_KP_MINUS:
key = '-';
break;
case K_KP_PLUS: case K_KP_PLUS:
key = '+';
break;
case K_KP_HOME: case K_KP_HOME:
key = '7';
break;
case K_KP_UPARROW: case K_KP_UPARROW:
key = '8';
break;
case K_KP_PGUP: case K_KP_PGUP:
key = '9';
break;
case K_KP_LEFTARROW:
key = '4';
break;
case K_KP_5: case K_KP_5:
key = '5';
break;
case K_KP_RIGHTARROW: case K_KP_RIGHTARROW:
key = '6';
break;
case K_KP_END: case K_KP_END:
key = '1';
break;
case K_KP_DOWNARROW: case K_KP_DOWNARROW:
key = '2';
break;
case K_KP_PGDN: case K_KP_PGDN:
key = '3';
break;
case K_KP_INS: case K_KP_INS:
key = '0';
break;
case K_KP_DEL: case K_KP_DEL:
key = '.';
break; break;
} }
if (key > 127) if ((key == K_BACKSPACE) || (key == K_LEFTARROW) || (key == K_KP_LEFTARROW))
{ {
return false;
}
switch (key)
{
case K_KP_LEFTARROW:
case K_LEFTARROW:
case K_BACKSPACE:
if (f->cursor > 0) if (f->cursor > 0)
{ {
memmove(&f->buffer[f->cursor - 1], memmove(&f->buffer[f->cursor - 1], &f->buffer[f->cursor],
&f->buffer[f->cursor],
strlen(&f->buffer[f->cursor]) + 1); strlen(&f->buffer[f->cursor]) + 1);
f->cursor--; f->cursor--;
@ -293,22 +261,25 @@ Field_Key(menufield_s *f, int key)
} }
} }
break; return true;
}
case K_KP_DEL: if ((key == K_DEL) || (key == K_KP_DEL))
case K_DEL: {
memmove(&f->buffer[f->cursor], &f->buffer[f->cursor + 1], memmove(&f->buffer[f->cursor], &f->buffer[f->cursor + 1],
strlen(&f->buffer[f->cursor + 1]) + 1); strlen(&f->buffer[f->cursor + 1]) + 1);
break; return true;
}
case K_KP_ENTER: if (key == K_ENTER || key == K_KP_ENTER || key == K_ESCAPE || key == K_TAB)
case K_ENTER: {
case K_ESCAPE:
case K_TAB:
return false; return false;
}
case K_SPACE: if ((key < 32) || (key > 127))
default: {
return false; /* non printable character */
}
if (!isdigit(key) && (f->generic.flags & QMF_NUMBERSONLY)) if (!isdigit(key) && (f->generic.flags & QMF_NUMBERSONLY))
{ {
@ -325,7 +296,6 @@ Field_Key(menufield_s *f, int key)
f->visible_offset++; f->visible_offset++;
} }
} }
}
return true; return true;
} }