Skip to content

Commit

Permalink
windows: Fix numpad arrow key scancodes with numlock off
Browse files Browse the repository at this point in the history
We should only perform the VK_LEFT, VK_UP, etc. mapping if none of the other
special mappings apply. This allows the scancode normalization for the number
pad to take place as intended.
  • Loading branch information
cgutman committed Aug 28, 2020
1 parent 1e2caac commit 771732e
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/video/windows/SDL_windowsevents.c
Expand Up @@ -83,17 +83,22 @@
#endif

static SDL_Scancode
VKeytoScancode(WPARAM vkey)
VKeytoScancodeFallback(WPARAM vkey)
{
switch (vkey) {
/* Windows generates this virtual keycode for Keypad 5 when NumLock is off.
case VK_CLEAR: return SDL_SCANCODE_CLEAR;
*/
case VK_LEFT: return SDL_SCANCODE_LEFT;
case VK_UP: return SDL_SCANCODE_UP;
case VK_RIGHT: return SDL_SCANCODE_RIGHT;
case VK_DOWN: return SDL_SCANCODE_DOWN;

default: return SDL_SCANCODE_UNKNOWN;
}
}

static SDL_Scancode
VKeytoScancode(WPARAM vkey)
{
switch (vkey) {
case VK_MODECHANGE: return SDL_SCANCODE_MODE;
case VK_SELECT: return SDL_SCANCODE_SELECT;
case VK_EXECUTE: return SDL_SCANCODE_EXECUTE;
Expand Down Expand Up @@ -219,6 +224,16 @@ WindowsScanCodeToSDLScanCode(LPARAM lParam, WPARAM wParam)
}
}
}

/* The on-screen keyboard can generate VK_LEFT and VK_RIGHT events without a scancode
* value set, however we cannot simply map these in VKeytoScancode() or we will be
* incorrectly handling the arrow keys on the number pad when NumLock is disabled
* (which also generate VK_LEFT, VK_RIGHT, etc in that scenario). Instead, we'll only
* map them if none of the above special number pad mappings applied. */
if (code == SDL_SCANCODE_UNKNOWN) {
code = VKeytoScancodeFallback(wParam);
}

return code;
}

Expand Down

0 comments on commit 771732e

Please sign in to comment.