mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Do not expect WM_CHAR if control or windows key is pressed (flutter/engine#27064)
This commit is contained in:
parent
bfd2785586
commit
a0cd9e9785
@ -371,11 +371,18 @@ WindowWin32::HandleMessage(UINT const message,
|
||||
// Check if this key produces a character. If so, the key press should
|
||||
// be sent with the character produced at WM_CHAR. Store the produced
|
||||
// keycode (it's not accessible from WM_CHAR) to be used in WM_CHAR.
|
||||
const unsigned int character = MapVirtualKey(wparam, MAPVK_VK_TO_CHAR);
|
||||
if (character > 0 && is_keydown_message) {
|
||||
//
|
||||
// Messages with Control or Win modifiers down are never considered as
|
||||
// character messages. This allows key combinations such as "CTRL + Digit"
|
||||
// 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) {
|
||||
keycode_for_char_message_ = wparam;
|
||||
break;
|
||||
}
|
||||
character = 0;
|
||||
unsigned int keyCode(wparam);
|
||||
const unsigned int scancode = (lparam >> 16) & 0xff;
|
||||
const bool extended = ((lparam >> 24) & 0x01) == 0x01;
|
||||
|
||||
@ -84,5 +84,27 @@ TEST(MockWin32Window, KeyDownPrintable) {
|
||||
window.InjectWindowMessage(WM_CHAR, 65, lparam);
|
||||
}
|
||||
|
||||
TEST(MockWin32Window, KeyDownWithCtrl) {
|
||||
MockWin32Window window;
|
||||
|
||||
// Simulate CONTROL pressed
|
||||
BYTE keyboard_state[256];
|
||||
memset(keyboard_state, 0, 256);
|
||||
keyboard_state[VK_CONTROL] = -1;
|
||||
SetKeyboardState(keyboard_state);
|
||||
|
||||
LPARAM lparam = CreateKeyEventLparam(30);
|
||||
|
||||
// Expect OnKey, but not OnText, because Control + Key is not followed by
|
||||
// WM_CHAR
|
||||
EXPECT_CALL(window, OnKey(65, 30, WM_KEYDOWN, 0, false, true)).Times(1);
|
||||
EXPECT_CALL(window, OnText(_)).Times(0);
|
||||
|
||||
window.InjectWindowMessage(WM_KEYDOWN, 65, lparam);
|
||||
|
||||
memset(keyboard_state, 0, 256);
|
||||
SetKeyboardState(keyboard_state);
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
} // namespace flutter
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user