Skip to content

[Windows] Normalize Shift key messages with a non-standard scan code - #193675

Merged
jtmcdole merged 2 commits into
flutter:masterfrom
palmoni5:fix/windows-shift-scancode
Nov 16, 2026
Merged

jtmcdole merged 2 commits into
flutter:masterfrom
palmoni5:fix/windows-shift-scancode

Conversation

@palmoni5

@palmoni5 palmoni5 commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

On Windows, a VK_SHIFT key message with the extended bit set or with a zero scan code makes Shift stay pressed in the framework indefinitely. This PR fixes that.

KeyboardKeyEmbedderHandler::GetPhysicalKey looks up scancode | (extended ? 0xE000 : 0) and falls back to windowsPlane | scancode, so such a message is recorded under a non-standard physical key (0x1600000036, 0x1600000000) with a Shift logical key. After that:

  • a regular key up resolves to the standard physical key, has no record, and is dropped;
  • SyncModifiersIfNeeded (MK_SHIFT on WM_MOUSEMOVE) and SynchronizeCriticalPressedStates (GetKeyState(VK_LSHIFT/VK_RSHIFT)) only check the standard ShiftLeft/ShiftRight records, so they never release it;
  • for a zero scan code, ResolveKeyCode also returns MapVirtualKey(0, MAPVK_VSC_TO_VK_EX) == 0.

User-visible effects: every click in a SelectionArea/TextField extends the selection, Tab moves focus backwards, and the mouse wheel scrolls horizontally.

The fix rewrites Shift key messages in KeyboardManager::HandleMessage to the standard ShiftLeft (0x2a) or ShiftRight (0x36) scan code with the extended bit cleared, before anything else reads them. Messages that already have a standard scan code are left unchanged. If a zero scan code is mapped to the wrong side, the existing GetKeyState synchronization corrects the state on the next key event.

Testing:

  • New tests ShiftRightWithExtendedBitIsReleasedByRegularKeyUp and ShiftWithZeroScanCodeIsReleasedByRegularKeyUp in keyboard_unittests.cc.
  • The same transformation, applied in an app runner as a window subclass in front of the engine, was checked against 3.47.2 with real messages. Without it, PostMessage of an extended/zero-scancode Shift down followed by a regular up and a mouse move leaves HardwareKeyboard.isShiftPressed == true. With it, Shift is released. Real SendInput input (left/right Shift, Shift + gray arrows, Shift + numpad with NumLock, injected scancode 0 / extended) behaves the same with and without it. Repro details: [Windows] Shift key randomly gets stuck in a "pressed down" state forever when using TextFields #181907 (comment)

Fixes #181907

Pre-launch Checklist

@google-cla

google-cla Bot commented Oct 1, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@github-actions github-actions Bot added engine flutter/engine related. See also e: labels. platform-windows Building on or for Windows specifically a: desktop Running on desktop team-windows Owned by the Windows platform team labels Oct 1, 2026
@palmoni5
palmoni5 force-pushed the fix/windows-shift-scancode branch 2 times, most recently from 2cd6fad to 629162c Compare October 1, 2026 20:29
@palmoni5
palmoni5 marked this pull request as ready for review October 1, 2026 20:31
@palmoni5
palmoni5 requested a review from a team as a code owner October 1, 2026 20:31

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a NormalizeShiftLParam helper function in the Windows keyboard manager to normalize the scan code and clear the extended bit of Shift key messages. This ensures that Shift key events originating from sources like IMEs or input injection resolve to standard physical keys and are correctly released. Corresponding unit tests have been added to verify this behavior. There are no review comments to evaluate, and no additional feedback is provided.

mattkae
mattkae previously approved these changes Oct 5, 2026

@mattkae mattkae left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good by me, thanks! @loic-sharma can you ack too?

@mattkae mattkae added the CICD Run CI/CD label Oct 5, 2026
@mattkae
mattkae requested a review from loic-sharma October 7, 2026 20:38
@flutter-dashboard

Copy link
Copy Markdown

This pull request executed golden file tests, but it has not been updated in a while (20+ days). Test results from Gold expire after as many days, so this pull request will need to be updated with a fresh commit in order to get results from Gold.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@mattkae
mattkae force-pushed the fix/windows-shift-scancode branch from 629162c to 94b0e16 Compare November 12, 2026 15:36
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Nov 12, 2026
@loic-sharma loic-sharma added the CICD Run CI/CD label Nov 13, 2026

@loic-sharma loic-sharma left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix looks good to me, but I left a comment on the behavior if Flutter ignores the key event and we redispatch the message.

@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Nov 13, 2026
@palmoni5
palmoni5 requested a review from loic-sharma November 13, 2026 00:28
@loic-sharma loic-sharma added the CICD Run CI/CD label Nov 13, 2026

@loic-sharma loic-sharma left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@mattkae mattkae added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 13, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 13, 2026
@auto-submit

auto-submit Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

auto label is removed for flutter/flutter/193675, Failed to enqueue flutter/flutter/193675 with HTTP 400: Pull request Required status check "Check Code Freeze" is expected..

@mattkae mattkae added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 13, 2026
@auto-submit

auto-submit Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

auto label is removed for flutter/flutter/193675, Failed to enqueue flutter/flutter/193675 with HTTP 400: Pull request Required status check "Check Code Freeze" is expected..

@loic-sharma loic-sharma added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 13, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 13, 2026
@auto-submit

auto-submit Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

auto label is removed for flutter/flutter/193675, Failed to enqueue flutter/flutter/193675 with HTTP 400: Pull request Required status check "Check Code Freeze" is expected..

@loic-sharma loic-sharma added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 13, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 13, 2026
@auto-submit

auto-submit Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

auto label is removed for flutter/flutter/193675, Failed to enqueue flutter/flutter/193675 with HTTP 400: Pull request Required status check "Check Code Freeze" is expected..

@loic-sharma

Copy link
Copy Markdown
Member

I can't get the code freeze check to pass. I'll try rebasing...

A VK_SHIFT key message with the extended bit set or with a zero scan code resolved to a non-standard physical key (windowsPlane | scancode). A regular key up for the standard physical key then had no record and was dropped, and the modifier synchronization (MK_SHIFT on mouse moves, GetKeyState on key events) only checks the standard ShiftLeft and ShiftRight records, so Shift stayed pressed in the framework indefinitely.

Rewrite Shift key messages to the standard ShiftLeft or ShiftRight scan code with the extended bit cleared before resolving them.

Fixes flutter#181907
Use the normalized Shift scan code for Flutter key events while retaining the original lParam in the native message session for unhandled-event redispatch.

Add regression coverage for extended-bit and zero-scan-code Shift down/up messages, checking both canonical Flutter events and unchanged native message fields. Correct the existing CtrlLeftUnhandled fixture to use VK_CONTROL for its release message.
@loic-sharma
loic-sharma force-pushed the fix/windows-shift-scancode branch from 83afd20 to 6333a72 Compare November 13, 2026 20:38
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Nov 13, 2026
@loic-sharma loic-sharma added CICD Run CI/CD autosubmit Merge PR when tree becomes green via auto submit App labels Nov 13, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 16, 2026
@auto-submit

auto-submit Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

auto label is removed for flutter/flutter/193675, Failed to enqueue flutter/flutter/193675 with HTTP 400: Pull request Required status check "Check Code Freeze" is expected..

@loic-sharma loic-sharma added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 16, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 16, 2026
@auto-submit

auto-submit Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

auto label is removed for flutter/flutter/193675, Failed to enqueue flutter/flutter/193675 with HTTP 400: Pull request Required status check "Check Code Freeze" is expected..

@mattkae mattkae added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 16, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 16, 2026
@auto-submit

auto-submit Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

auto label is removed for flutter/flutter/193675, Failed to enqueue flutter/flutter/193675 with HTTP 400: Pull request Required status check "Check Code Freeze" is expected..

@jtmcdole
jtmcdole added this pull request to the merge queue Nov 16, 2026
Merged via the queue into flutter:master with commit 6b06d15 Nov 16, 2026
36 checks passed
@palmoni5
palmoni5 deleted the fix/windows-shift-scancode branch November 16, 2026 20:46
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Nov 17, 2026
flutter/flutter@d8bd864...2f09f96

2026-11-17 [email protected] Analyze every flutter create template, and fix the package_ffi lint (flutter/flutter#196165)
2026-11-17 [email protected] Roll Dart SDK from 50debf3c9757 to 26e38955d9d4 (3 revisions) (flutter/flutter#196772)
2026-11-17 [email protected] Manual roll ICU from b09986242cfb to d3c612f44146 (1 revision) (flutter/flutter#196713)
2026-11-17 [email protected] Roll Skia from 4f6b3a8d8565 to 503a380ebecc (19 revisions) (flutter/flutter#196768)
2026-11-17 [email protected] iOS: Don't mock UIView animations in keyboard spring animation test (flutter/flutter#196755)
2026-11-17 [email protected] [flutter_tools] Preserve index.html across --web-content-hash transitions (flutter/flutter#196491)
2026-11-17 [email protected] Fix TextStyle background color fade-out when lerping to null (flutter/flutter#196153)
2026-11-17 [email protected] Update desktop engine TESTOWNERS (flutter/flutter#196732)
2026-11-17 [email protected] [flutter_tools] Do not copy app-only build type properties onto library plugins (flutter/flutter#196692)
2026-11-17 [email protected] [flutter_tools] Remove service and runner ambient context getters (flutter/flutter#196571)
2026-11-17 [email protected] Bump customer tests (flutter/flutter#196740)
2026-11-17 [email protected] Take customer_testing_flame out of bringup (flutter/flutter#196570)
2026-11-17 [email protected] [devicelab] Read AssetManifest.bin from the APK in flavors_test (flutter/flutter#196736)
2026-11-17 [email protected] [flutter_tools] Fix flaky tool_tests_general by moving spawnUri tests to integration shard (flutter/flutter#195999)
2026-11-17 [email protected] Roll Dart SDK from 3e069c6fdbde to 50debf3c9757 (2 revisions) (flutter/flutter#196706)
2026-11-16 [email protected] [web] Record build finish synchronously in renderScene and fix dropped frame timings (flutter/flutter#195947)
2026-11-16 [email protected] Do not reveal obscured character when input is rejected by inputFormatters (flutter/flutter#195022)
2026-11-16 [email protected] Cla draft follow up: add waiting for response (flutter/flutter#196686)
2026-11-16 [email protected] Roll pub packages (flutter/flutter#196684)
2026-11-16 [email protected] Roll Packages from 015df97 to 4c6a7d3 (8 revisions) (flutter/flutter#196681)
2026-11-16 [email protected] Skip Vulkan impeller_unittests on macOS (flutter/flutter#196282)
2026-11-16 [email protected] Move the task runners out of Flutter Engine (flutter/flutter#196267)
2026-11-16 [email protected] [FGP] Add Flutter assets after AGP's asset merge so dotfiles are pack… (flutter/flutter#196465)
2026-11-16 [email protected] iOS: Add Obj-C model for platform view composition params (flutter/flutter#196498)
2026-11-16 [email protected] [Windows] Normalize Shift key messages with a non-standard scan code (flutter/flutter#193675)
2026-11-16 [email protected] Roll Skia from 118eaff3deb4 to 4f6b3a8d8565 (3 revisions) (flutter/flutter#196672)
2026-11-16 [email protected] Roll Dart SDK from c91e8b6674e2 to 3e069c6fdbde (4 revisions) (flutter/flutter#196669)

If this roll has caused a breakage, revert this CL and set the roller
to dry run mode using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: desktop Running on desktop CICD Run CI/CD engine flutter/engine related. See also e: labels. platform-windows Building on or for Windows specifically team-windows Owned by the Windows platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Windows] Shift key randomly gets stuck in a "pressed down" state forever when using TextFields

4 participants