Fix duplicated keys with CONTROL key toggled (flutter/engine#27301)

This commit is contained in:
Matej Knopp
2021-07-15 22:26:02 +02:00
committed by GitHub
parent fe39238f25
commit 3c4ae00555
2 changed files with 26 additions and 2 deletions

View File

@@ -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;
}

View File

@@ -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