Skip to content

Fix/windows simulator arrow key#910

Open
siudesu wants to merge 1 commit intocoronalabs:masterfrom
siudesu:fix/windows-simulator-arrow-key
Open

Fix/windows simulator arrow key#910
siudesu wants to merge 1 commit intocoronalabs:masterfrom
siudesu:fix/windows-simulator-arrow-key

Conversation

@siudesu
Copy link
Copy Markdown

@siudesu siudesu commented Apr 20, 2026

This is a related to #405 (Simulator performance fix: treat repeated keys as handled)

Summary
On the Windows Simulator, pressing the Up or Down arrow keys causes a latency spike, noticeable visually when pressed repeatedly.

Root cause
When a Lua key listener does not return true, the WM_KEYDOWN message is left unhandled and falls through to DefWindowProc. Win32 keyboard navigation routes VK_UP and VK_DOWN to a split button control present in the simulator UI, triggering a pair of synchronous BCM_SETDROPDOWNSTATE messages (set True, immediately set False) on every keypress. This synchronous round-trip into the button control's window procedure disrupts the update/render loop's timing. VK_LEFT/VK_RIGHT do not trigger this behavior.
This was confirmed via MS Spy++ message logging on the render surface window:

<000231> 000408EA P WM_KEYDOWN nVirtKey:VK_DOWN cRepeat:1 ScanCode:50 fExtended:1 fAltDown:0 fRepeat:0 fUp:0
<000232> 000408EA S BCM_SETDROPDOWNSTATE fDropDown:True
<000233> 000408EA R BCM_SETDROPDOWNSTATE fSucceeded:False
<000234> 000408EA S BCM_SETDROPDOWNSTATE fDropDown:False
<000235> 000408EA R BCM_SETDROPDOWNSTATE fSucceeded:False

Fix
In the else branch of the key event handler (i.e. when Lua did not handle the key), VK_UP and VK_DOWN are now explicitly marked as handled so they never reach DefWindowProc. This is consistent with how the back key is already handled in the same branch.

Testing

  • Confirmed via Spy++ that BCM_SETDROPDOWNSTATE is no longer triggered by Up/Down keypresses after the fix
  • No jitter/spikes detected on a profiler when pressing Up/Down arrow keys in the Windows Simulator
  • Left/Right arrow keys, character keys, and modifier keys unaffected
  • Back key behavior unaffected
  • Lua key listeners that return true continue to work as before
  • Navigating Simulator UI with arrow keys unaffected

@siudesu siudesu requested a review from Shchvova as a code owner April 20, 2026 09:02
@siudesu
Copy link
Copy Markdown
Author

siudesu commented Apr 20, 2026

Whoops. meant to include only 138ec32

@clang-clang-clang
Copy link
Copy Markdown
Contributor

clang-clang-clang commented Apr 20, 2026

Whoops. meant to include only 138ec32

Make sure you keep the copy on your local! Then,
Just force-push the from branch to ensure all intended changes are included, it will be fine.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 20, 2026

CLA assistant check
All committers have signed the CLA.

… split button

When a Lua key listener does not return true, unhandled WM_KEYDOWN messages fall through to DefWindowProc.
Win32 keyboard navigation routes VK_UP and VK_DOWN to a split button control in the simulator, which triggers a pair of synchronous BCM_SETDROPDOWNSTATE messages (True then immediately False) on every keypress.
This synchronous round-trip into the button control's window procedure disrupts update/render loop timing.
VK_LEFT/VK_RIGHT do not exhibit this behavior.

Fix: mark VK_UP and VK_DOWN as handled in the unhandled-key else-branch so they never reach DefWindowProc.

Verified via Spy++ which confirmed BCM_SETDROPDOWNSTATE firing on every VK_UP/VK_DOWN keypress and its absence on VK_LEFT/VK_RIGHT.

<000229> 000408EA P WM_PAINT hdc:00000000
<000230> 000408EA P message:0x0500 [User-defined:WM_USER+256] wParam:00000006 lParam:00000000
<000231> 000408EA P WM_KEYDOWN nVirtKey:VK_DOWN cRepeat:1 ScanCode:50 fExtended:1 fAltDown:0 fRepeat:0 fUp:0
<000232> 000408EA S BCM_SETDROPDOWNSTATE fDropDown:True
<000233> 000408EA R BCM_SETDROPDOWNSTATE fSucceeded:False
<000234> 000408EA S BCM_SETDROPDOWNSTATE fDropDown:False
<000235> 000408EA R BCM_SETDROPDOWNSTATE fSucceeded:False
<000236> 000408EA P WM_PAINT hdc:00000000
@siudesu siudesu force-pushed the fix/windows-simulator-arrow-key branch from 138ec32 to 25fb8ad Compare April 20, 2026 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants