Skip to content

Commit

Permalink
[win] Fix the repeat field of KeyDown event
Browse files Browse the repository at this point in the history
0-15 bits of the LPARAM argument aren't the number of times that a
WM_KEYDOWN message was auto-repeated by just pressing a key down. It's
the number of enqueued messages that are not yet processed.

Anyway we can use the bit 30 of the LPARAM to know if the WM_KEYDOWN
message was generated when the key was previously up (the user pressed
it for the first time) or down (the user keeps pressing the key so
more messages are received from Windows).

Related to:
aseprite/aseprite#3684
aseprite/aseprite#4063
#69
#70
  • Loading branch information
dacap committed Oct 2, 2023
1 parent 10c99f1 commit 58709a0
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions os/win/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1679,7 +1679,7 @@ LRESULT WindowWin::wndProc(UINT msg, WPARAM wparam, LPARAM lparam)
ev.setModifiers(get_modifiers_from_last_win32_message());
ev.setScancode(ourScancode);
ev.setUnicodeChar(0);
ev.setRepeat(std::max(0, int((lparam & 0xffff)-1)));
ev.setRepeat(lparam & (1 << 30) ? 1: 0);

KEY_TRACE("KEYDOWN vk=%d scancode=%d->%d modifiers=%d\n",
vk, scancode, ev.scancode(), ev.modifiers());
Expand Down Expand Up @@ -1725,7 +1725,7 @@ LRESULT WindowWin::wndProc(UINT msg, WPARAM wparam, LPARAM lparam)
ev.setModifiers(get_modifiers_from_last_win32_message());
ev.setScancode(win32vk_to_scancode(wparam));
ev.setUnicodeChar(0);
ev.setRepeat(std::max(0, int((lparam & 0xffff)-1)));
ev.setRepeat(lparam & (1 << 30) ? 0: 1);
queueEvent(ev);

// TODO If we use native menus, this message should be given
Expand Down

0 comments on commit 58709a0

Please sign in to comment.