diff --git a/engine/src/flutter/shell/platform/windows/window_win32.cc b/engine/src/flutter/shell/platform/windows/window_win32.cc index f827acc0e8..f7c8e231a3 100644 --- a/engine/src/flutter/shell/platform/windows/window_win32.cc +++ b/engine/src/flutter/shell/platform/windows/window_win32.cc @@ -377,8 +377,8 @@ WindowWin32::HandleMessage(UINT const message, // to properly produce key down events even though `MapVirtualKey` returns // a valid character. See https://github.com/flutter/flutter/issues/85587. unsigned int character = MapVirtualKey(wparam, MAPVK_VK_TO_CHAR); - if (character > 0 && is_keydown_message && GetKeyState(VK_CONTROL) == 0 && - GetKeyState(VK_LWIN) == 0 && GetKeyState(VK_RWIN) == 0) { + if (character > 0 && is_keydown_message && GetKeyState(VK_CONTROL) >= 0 && + GetKeyState(VK_LWIN) >= 0 && GetKeyState(VK_RWIN) >= 0) { keycode_for_char_message_ = wparam; break; } diff --git a/engine/src/flutter/shell/platform/windows/window_win32_unittests.cc b/engine/src/flutter/shell/platform/windows/window_win32_unittests.cc index 846c121779..ce54155cd7 100644 --- a/engine/src/flutter/shell/platform/windows/window_win32_unittests.cc +++ b/engine/src/flutter/shell/platform/windows/window_win32_unittests.cc @@ -106,5 +106,29 @@ TEST(MockWin32Window, KeyDownWithCtrl) { SetKeyboardState(keyboard_state); } +TEST(MockWin32Window, KeyDownWithCtrlToggled) { + MockWin32Window window; + + // Simulate CONTROL toggled + BYTE keyboard_state[256]; + memset(keyboard_state, 0, 256); + keyboard_state[VK_CONTROL] = 1; + SetKeyboardState(keyboard_state); + + LPARAM lparam = CreateKeyEventLparam(30); + + // OnKey shouldn't be called until the WM_CHAR message. + EXPECT_CALL(window, OnKey(65, 30, WM_KEYDOWN, 65, false, true)).Times(0); + // send a "A" key down event. + window.InjectWindowMessage(WM_KEYDOWN, 65, lparam); + + EXPECT_CALL(window, OnKey(65, 30, WM_KEYDOWN, 65, false, true)).Times(1); + EXPECT_CALL(window, OnText(_)).Times(1); + window.InjectWindowMessage(WM_CHAR, 65, lparam); + + memset(keyboard_state, 0, 256); + SetKeyboardState(keyboard_state); +} + } // namespace testing } // namespace flutter