Skip to content

Commit ac16fc8

Browse files
committed
Fixing syntax errors
1 parent 61d35dc commit ac16fc8

File tree

3 files changed

+56
-36
lines changed

3 files changed

+56
-36
lines changed

shell/platform/windows/flutter_windows_view.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,11 @@ class FlutterWindowsView : public WindowBindingHandlerDelegate {
143143
void SendText(const std::u16string&);
144144

145145
// Reports a raw keyboard message to Flutter engine.
146-
void SendKey(int key, int scancode, int action, char32_t character);
146+
void SendKey(int key,
147+
int scancode,
148+
int action,
149+
char32_t character,
150+
bool extended);
147151

148152
// Reports scroll wheel events to Flutter engine.
149153
void SendScroll(double x,

shell/platform/windows/key_event_handler.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ void KeyEventHandler::KeyboardHook(FlutterWindowsView* view,
110110
LPARAM extraInfo = GetMessageExtraInfo();
111111
if (extraInfo == kSynthesizedEvent) {
112112
// Don't pass messages that we synthesized to the framework again.
113+
std::cerr << "Skipping synthesized key for scancode " << scancode << " ("
114+
<< character << ")" << std::endl;
113115
return;
114116
}
115117
// TODO: Translate to a cross-platform key code system rather than passing
@@ -133,11 +135,11 @@ void KeyEventHandler::KeyboardHook(FlutterWindowsView* view,
133135
std::cerr << "Unknown key event action: " << action << std::endl;
134136
return;
135137
}
136-
channel_->Send(event, [action, extended, scancode](const uint8_t* reply,
137-
size_t reply_size) {
138+
channel_->Send(event, [action, extended, scancode, character](
139+
const uint8_t* reply, size_t reply_size) {
138140
auto decoded = flutter::JsonMessageCodec::GetInstance().DecodeMessage(
139141
reply, reply_size);
140-
bool handled = decoded[kHandledKey].GetBool();
142+
bool handled = (*decoded)[kHandledKey].GetBool();
141143
if (!handled) {
142144
// Since the framework didn't handle the event, we inject a newly
143145
// synthesized one. We let Windows figure out the virtual key and
@@ -153,7 +155,9 @@ void KeyEventHandler::KeyboardHook(FlutterWindowsView* view,
153155
key_event.dwExtraInfo = static_cast<ULONG_PTR>(kSynthesizedEvent);
154156
INPUT input_event;
155157
input_event.type = INPUT_KEYBOARD;
156-
input_event.ki = &key_event;
158+
input_event.ki = key_event;
159+
std::cerr << "Synthesizing key for scancode " << scancode << " ("
160+
<< character << ")" << std::endl;
157161
UINT accepted = SendInput(1, &input_event, sizeof(input_event));
158162
if (accepted != 1) {
159163
std::cerr << "Unable to synthesize event for unhandled keyboard event "

shell/platform/windows/win32_window.cc

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ Win32Window::HandleMessage(UINT const message,
116116
int xPos = 0, yPos = 0;
117117
UINT width = 0, height = 0;
118118
UINT button_pressed = 0;
119+
LPARAM extraInfo = GetMessageExtraInfo();
120+
if (extraInfo == 0xbaddecaf) {
121+
// Don't pass messages that we synthesized to the framework again.
122+
std::cerr << "Found Extra Info synthesized key for scancode " << scancode << " ("
123+
<< character << ")" << std::endl;
124+
}
119125

120126
switch (message) {
121127
case kWmDpiChangedBeforeParent:
@@ -237,39 +243,45 @@ Win32Window::HandleMessage(UINT const message,
237243
OnText(text);
238244
}
239245

240-
// All key presses that generate a character should be sent from
241-
// WM_CHAR. In order to send the full key press information, the keycode
242-
// is persisted in keycode_for_char_message_ obtained from WM_KEYDOWN.
243-
if (keycode_for_char_message_ != 0) {
244-
const unsigned int scancode = (lparam >> 16) & 0xff;
245-
OnKey(keycode_for_char_message_, scancode, WM_KEYDOWN, code_point);
246-
keycode_for_char_message_ = 0;
247-
}
248-
break;
249-
}
250-
case WM_KEYDOWN:
251-
case WM_SYSKEYDOWN:
252-
case WM_KEYUP:
253-
case WM_SYSKEYUP:
254-
const bool is_keydown_message =
255-
(message == WM_KEYDOWN || message == WM_SYSKEYDOWN);
256-
// Check if this key produces a character. If so, the key press should
257-
// be sent with the character produced at WM_CHAR. Store the produced
258-
// keycode (it's not accessible from WM_CHAR) to be used in WM_CHAR.
259-
const unsigned int character = MapVirtualKey(wparam, MAPVK_VK_TO_CHAR);
260-
if (character > 0 && is_keydown_message) {
261-
keycode_for_char_message_ = wparam;
246+
// All key presses that generate a character should be sent from
247+
// WM_CHAR. In order to send the full key press information, the keycode
248+
// is persisted in keycode_for_char_message_ obtained from WM_KEYDOWN.
249+
if (keycode_for_char_message_ != 0) {
250+
const unsigned int scancode = (lparam >> 16) & 0xff;
251+
const bool extended = ((lparam >> 24) & 0x01) == 0x01;
252+
window->OnKey(keycode_for_char_message_, scancode, WM_KEYDOWN,
253+
code_point, extended);
254+
keycode_for_char_message_ = 0;
255+
}
262256
break;
263257
}
264-
unsigned int keyCode(wparam);
265-
const unsigned int scancode = (lparam >> 16) & 0xff;
266-
// If the key is a modifier, get its side.
267-
if (keyCode == VK_SHIFT || keyCode == VK_MENU || keyCode == VK_CONTROL) {
268-
keyCode = MapVirtualKey(scancode, MAPVK_VSC_TO_VK_EX);
269-
}
270-
const int action = is_keydown_message ? WM_KEYDOWN : WM_KEYUP;
271-
OnKey(keyCode, scancode, action, 0);
272-
break;
258+
case WM_KEYDOWN:
259+
case WM_SYSKEYDOWN:
260+
case WM_KEYUP:
261+
case WM_SYSKEYUP:
262+
const bool is_keydown_message =
263+
(message == WM_KEYDOWN || message == WM_SYSKEYDOWN);
264+
// Check if this key produces a character. If so, the key press should
265+
// be sent with the character produced at WM_CHAR. Store the produced
266+
// keycode (it's not accessible from WM_CHAR) to be used in WM_CHAR.
267+
const unsigned int character = MapVirtualKey(wparam, MAPVK_VK_TO_CHAR);
268+
if (character > 0 && is_keydown_message) {
269+
keycode_for_char_message_ = wparam;
270+
break;
271+
}
272+
unsigned int keyCode(wparam);
273+
const unsigned int scancode = (lparam >> 16) & 0xff;
274+
const bool extended = ((lparam >> 24) & 0x01) == 0x01;
275+
// If the key is a modifier, get its side.
276+
if (keyCode == VK_SHIFT || keyCode == VK_MENU ||
277+
keyCode == VK_CONTROL) {
278+
keyCode = MapVirtualKey(scancode, MAPVK_VSC_TO_VK_EX);
279+
}
280+
const int action = is_keydown_message ? WM_KEYDOWN : WM_KEYUP;
281+
window->OnKey(keyCode, scancode, action, 0, extended);
282+
break;
283+
}
284+
return DefWindowProc(hwnd, message, wparam, lparam);
273285
}
274286

275287
return DefWindowProc(window_handle_, message, wparam, lparam);

0 commit comments

Comments
 (0)