# HG changeset patch # User Cameron Gutman # Date 1598576092 25200 # Thu Aug 27 17:54:52 2020 -0700 # Branch numpad_arrows # Node ID b46c3ba3fe14df49c804f6bd00f1047581c15436 # Parent 56cb1e9e9015462a00c250a35a8b01ce4902729e windows: Fix numpad arrow key scancodes with numlock off 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. diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c --- a/src/video/windows/SDL_windowsevents.c +++ b/src/video/windows/SDL_windowsevents.c @@ -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; @@ -219,6 +224,16 @@ } } } + + /* 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; }