From 58709a07c97243447897147c118c4e0005bbd162 Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 2 Oct 2023 19:54:42 -0300 Subject: [PATCH] [win] Fix the repeat field of KeyDown event 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: https://github.com/aseprite/aseprite/issues/3684 https://github.com/aseprite/aseprite/pull/4063 https://github.com/aseprite/laf/pull/69 https://github.com/aseprite/laf/pull/70 --- os/win/window.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/os/win/window.cpp b/os/win/window.cpp index 02121c7f4..1914cf877 100644 --- a/os/win/window.cpp +++ b/os/win/window.cpp @@ -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()); @@ -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