Repository navigation
Commit 774b051
authored
[Windows] Fix Space input after Alt+Space with previous Microsoft IME (flutter#192105)
<!--
Thanks for filing a pull request!
Reviewers are typically assigned within a week of filing a request.
To learn more about code review, see our documentation on Tree Hygiene:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
-->
Fixes flutter#189495
## Description
After `Alt+Space` opens the Windows system menu, the Space key-up does
not always reach Flutter while the native menu is active. Flutter can
therefore retain a stale pressed record that maps the physical Space key
to the logical Space key.
With **Use previous version of Microsoft IME** enabled, the next
physical Space press can first arrive as a fresh
`WM_KEYDOWN(VK_PROCESSKEY)` with the Space scan code, followed by the
translated `WM_KEYDOWN(VK_SPACE)` event.
The existing stale-state recovery synthesizes the missing Space key-up,
but then continues processing the `VK_PROCESSKEY` event and records it
as the logical key for physical Space. The following translated
`VK_SPACE` event consequently inherits `VK_PROCESSKEY` as its sequence
logical key and is filtered as an IME event. Space input then remains
unavailable.
When this state is detected, the handler now synthesizes the missing
key-up and filters the fresh `VK_PROCESSKEY` event without recording it.
The following translated `VK_SPACE` event is then processed normally.
The observed failing event is `WM_KEYDOWN(VK_PROCESSKEY)`. The
implementation reuses the handler's existing definition of a key-down
event, which also includes `WM_SYSKEYDOWN`, so the same pressed-state
invariant is preserved for system key-down messages. The early path
additionally requires an existing record for the same physical key and a
previous-key-state bit indicating a fresh press.
Normal IME events without a stale pressed record, key-up events, and
repeated key-down events continue through the existing paths.
Microsoft documents the previous IME setting here: [Revert to a previous
version of an Input Method Editor
(IME)](https://support.microsoft.com/en-us/windows/hardware/input-devices/revert-to-a-previous-version-of-an-input-method-editor-ime)
## Win32 behavior
Microsoft documents that:
-
[`WM_SYSKEYDOWN`](https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-syskeydown)
is posted when Alt is held while another key is pressed.
- Bit 30 of
[`WM_KEYDOWN`](https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-keydown)
indicates the previous key state, allowing a fresh down transition to be
distinguished from an auto-repeat.
- An IME changes the virtual-key value of an already processed key
message to `VK_PROCESSKEY`, as described by
[`ImmGetVirtualKey`](https://learn.microsoft.com/en-us/windows/win32/api/imm/nf-imm-immgetvirtualkey).
-
[`SC_KEYMENU`](https://learn.microsoft.com/en-us/windows/win32/menurc/wm-syscommand)
identifies a window-menu request caused by a keystroke.
Here, `229` is `VK_PROCESSKEY`, `32` is `VK_SPACE`, and scan code `57`
is the physical Space key.
<details>
<summary>Diagnostic log excerpts</summary>
### Current Microsoft IME
The next Space press arrives directly as `VK_SPACE`. The existing
stale-state recovery handles this case:
```text
[flutter#189495][child-window] message=256 wparam=32 scan_code=57 extended=0 context=0 was_down=0 transition=0 space_async_down=1 alt_async_down=0
[flutter#189495][child-window] message=258 wparam=32 scan_code=57 extended=0 context=0 was_down=0 transition=0 space_async_down=1 alt_async_down=0
[flutter#189495][embedder:entry] action=256 key=32 scancode=57 character=32 extended=0 was_down=0 physical_key=458796 logical_key=32 had_record=1 last_logical_record=32 pressed_count=1
[flutter#189495][embedder:stale-record] physical_key=458796 last_logical_record=32 incoming_logical_key=32
```
### Previous Microsoft IME before this change
A fresh `VK_PROCESSKEY` arrives first. The existing recovery replaces
the logical record with `229`, so the translated `VK_SPACE` event is
also filtered:
```text
[flutter#189495][window] WM_KEYDOWN message=256 wparam=229 scan_code=57 extended=0 context=0 was_down=0 transition=0 space_async_down=1 alt_async_down=0 has_focus=1 is_active=0 is_foreground=0
[flutter#189495][embedder:entry] action=256 key=229 scancode=57 character=0 extended=0 was_down=0 physical_key=458796 logical_key=229 had_record=1 last_logical_record=32 pressed_count=1
[flutter#189495][embedder:stale-record] physical_key=458796 last_logical_record=32 incoming_logical_key=229
[flutter#189495][window] WM_KEYDOWN message=256 wparam=32 scan_code=57 extended=0 context=0 was_down=0 transition=0 space_async_down=1 alt_async_down=0 has_focus=1 is_active=0 is_foreground=0
[flutter#189495][window] WM_CHAR message=258 wparam=32 scan_code=57 extended=0 context=0 was_down=0 transition=0 space_async_down=1 alt_async_down=0 has_focus=1 is_active=0 is_foreground=0
[flutter#189495][embedder:entry] action=256 key=32 scancode=57 character=32 extended=0 was_down=0 physical_key=458796 logical_key=32 had_record=1 last_logical_record=229 pressed_count=1
[flutter#189495][embedder:ime-filter] action=256 key=32 sequence_logical_key=229 had_record=1
```
### Previous Microsoft IME after this change
The stale Space record is released while filtering the fresh
`VK_PROCESSKEY`. The translated `VK_SPACE` event then arrives with no
stale record and is processed as a normal key-down:
```text
[flutter#189495][window] message=256 wparam=229 scan_code=57 extended=0 context=0 was_down=0 transition=0
[flutter#189495][embedder:entry] action=256 key=229 scancode=57 character=0 extended=0 was_down=0 physical_key=458796 logical_key=229 had_record=1 last_logical_record=32 pressed_count=1
[flutter#189495][embedder:synthesize-up] physical_key=458796 logical_key=32 pressed_count_before=1
[flutter#189495][embedder:synthesize-up] pressed_count_after=0
[flutter#189495][window] message=256 wparam=32 scan_code=57 extended=0 context=0 was_down=0 transition=0
[flutter#189495][window] message=258 wparam=32 scan_code=57 extended=0 context=0 was_down=0 transition=0
[flutter#189495][embedder:entry] action=256 key=32 scancode=57 character=32 extended=0 was_down=0 physical_key=458796 logical_key=32 had_record=0 last_logical_record=0 pressed_count=0
[flutter#189495][embedder:sequence] key=32 sequence_logical_key=32 ime_filter=0
[flutter#189495][embedder:decision] down result_logical_key=32
```
</details>
## Screenshot
https://github.com/user-attachments/assets/ae2a66c1-6536-442c-a430-c8fdb0dc1c6e
## Pre-launch Checklist
- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [AI contribution guidelines] and understand my
responsibilities, or I am not using AI tools.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant in-code documentation (doc comments with
`///`).
- [x] If this PR introduces a new feature or capability, I created and
linked a website documentation issue or PR in [flutter/website] (or
verified none is needed).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.
If you need help, consider asking for advice on the #hackers-new channel
on [Discord].
If this change needs to override an active code freeze, provide a
comment explaining why. The code freeze workflow can be overridden by
code reviewers. See pinned issues for any active code freezes with
guidance.
**Note**: The Flutter team is currently trialing the use of [Gemini Code
Assist for
GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code).
Comments from the `gemini-code-assist` bot should not be taken as
authoritative feedback from the Flutter team. If you find its comments
useful you can update your code accordingly, but if you are unsure or
disagree with the feedback, please feel free to wait for a Flutter team
member's review for guidance on which automated comments should be
addressed.
<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[AI contribution guidelines]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[flutter/website]: https://github.com/flutter/website
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md1 parent 37a1588 commit 774b051
2 files changed
Lines changed: 76 additions & 2 deletions
File tree
- engine/src/flutter/shell/platform/windows
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
170 | 180 | | |
171 | 181 | | |
172 | 182 | | |
| |||
183 | 193 | | |
184 | 194 | | |
185 | 195 | | |
186 | | - | |
187 | | - | |
188 | 196 | | |
189 | 197 | | |
190 | 198 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| 78 | + | |
78 | 79 | | |
79 | 80 | | |
80 | 81 | | |
| |||
327 | 328 | | |
328 | 329 | | |
329 | 330 | | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
330 | 396 | | |
331 | 397 | | |
332 | 398 | | |
| |||
0 commit comments