Fix duplicated keys with CONTROL key toggled (flutter/engine#27301)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user