Skip to content

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

Closed

Description

@adrianflutur

Steps to reproduce

The problem is that sometimes, when editing text inside a TextField using the Shift key, the Flutter app will keep the Shift key stuck in a "pressed down" state forever.

It happens quite randomly, but generally what seems to trigger the problem is this:

  1. Focus on a TextField widget and write something
  2. Use the Shift key, maybe combined with the arrow keys as well (press Shift and select some text with the arrow keys, or press Shift and click with your mouse somewhere within the TextField, ...). Also try to unfocus the whole application (click on your desktop, other app, etc), then re-focus the Flutter app
  3. At some point you will notice that the Shift key is logically stuck in a "pressed down" state forever inside the Flutter app. You cannot deactivate/unpress it, no matter what

This issue seems to be related to these

but it seems the problem is still here in Flutter v3.32.8.

Here are some signs to notice when this problem starts to happen:

  • when you edit some text inside a TextField, parts of the text are automatically selected (without you pressing the Shift key) -> you can see this happening in the video
  • you cannot scroll vertical scroll views with your mouse wheel anymore because the Shift key is stuck in the down state, so you can only scroll horizontally now
  • focus groups will now focus backwards (i.e. when you press the Tab key to move to the next focus, the app will actually focus the previous focusable element) -> you can see this happening in the video

Expected results

Expected = I can use the Shift key normally

Actual results

Actual = The Shift key is stuck in a "pressed down" state forever, and you have to restart the app to "fix it", but it will happen again at some point

Code sample

Code sample

I can't paste the actual code from the video, but the widgets are literally just two TextFields with a border and nothing else.
Any TextField will do.

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Container(
          alignment: Alignment.center,
          padding: const EdgeInsets.all(16),
          child: const TextField(),
        ),
      ),
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration
2026-02-04.14-05-43.mp4

Logs

No response

Flutter Doctor output

Doctor output
$ flutter doctor -v
[✓] Flutter (Channel stable, 3.32.8, on Microsoft Windows [Version 10.0.22631.6199], locale en-001) [407ms]
    • Flutter version 3.32.8 on channel stable at C:\Users\ady_f\fvm\versions\3.32.8
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision edada7c56e (6 months ago), 2025-07-25 14:08:03 +0000
    • Engine revision ef0cd00091
    • Dart version 3.8.1
    • DevTools version 2.45.1

[✓] Windows Version (11 Home 64-bit, 23H2, 2009) [2.7s]

[✓] Android toolchain - develop for Android devices (Android SDK version 36.0.0) [1,828ms]
    • Android SDK at D:\Software\dev\android-sdk
    • Platform android-36, build-tools 36.0.0
    • Java binary at: C:\Program Files\OpenJDK\jdk-18.0.2\bin\java
      This JDK is specified in your Flutter configuration.
      To change the current JDK, run: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (build 18.0.2+9-61)
    • All Android licenses accepted.

[✓] Chrome - develop for the web [100ms]
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[✓] Visual Studio - develop Windows apps (Visual Studio Community 2019 16.11.18) [99ms]
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
    • Visual Studio Community 2019 version 16.11.32802.440
    • Windows 10 SDK version 10.0.19041.0

[✓] Android Studio (version 2025.1.4) [28ms]
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 21.0.8+-14018985-b1038.68)

[✓] VS Code, 64-bit edition (version 1.102.2) [26ms]
    • VS Code at C:\Program Files\Microsoft VS Code
    • Flutter extension version 3.128.0

[✓] Connected device (3 available) [221ms]
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.22631.6199]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 144.0.7559.110
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 144.0.3719.92

[✓] Network resources [359ms]
    • All expected network resources are available.

• No issues found!

Activity

  1. changed the title [-][Windows] Shift key randomly gets stuck in a "pressed down" state forever[/-] [+][Windows] Shift key randomly gets stuck in a "pressed down" state forever when using TextFields[/+] on Feb 4, 2026
  2. added
    in triage
    and removed
    in triage
    on Feb 12, 2026
  3. added
    in triage
    on Feb 17, 2026
  4. saurabh-mirajkar commented on Feb 17, 2026

    @saurabh-mirajkar
    Contributor

    @adrianflutur Thanks for the report.

  5. added
    platform-windows
    team-windows
    a: text input
    and removed
    in triage
    on Feb 17, 2026
  6. added
    fyi-text-input
    P2
    triaged-windows
    on Feb 25, 2026
  7. added
    triaged-text-input
    on Mar 5, 2026
  8. removed
    fyi-text-input
    triaged-text-input
    on Mar 5, 2026
  9. yuuuuuzj commented on Jun 3, 2026

    @yuuuuuzj

    I also found that if I press Shift first and then click inside the input box, the text between the cursor position and the clicked position gets selected. While still holding Shift, I press Tab, then switch focus to another application or window with the mouse. After releasing the keys and switching back to the original window, pressing Shift again causes it to behave as if Tab were pressed.

  10. yuuuuuzj commented on Jun 9, 2026

    @yuuuuuzj

    {
    "log_level": "i",
    "msg": "KeyDownEvent: Shift Right, physical=null(usage=0x1600000036), composing=false, pressedKeys=[Shift Right], physicalPressed=[?(0x1600000036)]"
    }

    Why is the usage of Shift Right 0x1600000036?

  11. yuuuuuzj commented on Jun 29, 2026

    @yuuuuuzj

    { "log_level": "i", "msg": "KeyDownEvent: Shift Right, physical=null(usage=0x1600000036), composing=false, pressedKeys=[Shift Right], physicalPressed=[?(0x1600000036)]" }

    Why is the usage of Shift Right 0x1600000036?

    I wasn't able to reproduce this issue under normal conditions. However, I managed to reproduce it by modifying the behavior on the NA side.

    I hooked the message handling and, whenever the editor regained focus, I checked whether Shift was still pressed. If it wasn't, I injected a Shift key-up event without the extended flag.

    After doing that, I could consistently reproduce the issue with the following steps:

    Switch to the Windows Microsoft Chinese IME.
    Press Shift.
    Move focus away from the application.
    Release Shift.
    Switch back to the application.

    This makes me suspect that the problem may be related to how the extended flag is handled.
    @saurabh-mirajkar @loic-sharma @mbcorona You could try reproducing the issue this way.

    I can also reproduce this on Flutter 3.44.4. With the Microsoft Chinese IME enabled, press and hold both the left and right Shift keys simultaneously, switch focus away from the application, release both Shift keys, and then return focus to the Flutter text field. The issue is reproducible.

  12. adrianflutur commented on Jul 8, 2026

    @adrianflutur
    Author

    Hey @yuuuuuzj, sorry for the delay. I've seen your message but now it seems to be deleted.

    @adrianflutur Did you manage to resolve this issue yourself afterward?

    We did not manage to solve this issue, but one thing we noticed is that the problem happens way more often in debug mode and a lot less in production, for some reason. So, it is not too critical for us at this moment, although it would be nice to figure out what's going on. Unfortunately I haven't had enough time to dig deep into it myself.

  13. yuuuuuzj commented on Jul 16, 2026

    @yuuuuuzj

    I think the root cause is that the engine maintains an internal key state array. Once stale key states cannot be cleared through the normal key event sequence, persistent stuck-key issues occur.

    In our application, I've observed two scenarios that have the greatest impact:

    The Shift key's extended flag is reported incorrectly.
    IMEs generate virtual key events whose scan code is 0.

    Neither of these scenarios is covered by the engine's current stale-key cleanup strategy.

  14. palmoni5 commented on Oct 1, 2026

    @palmoni5
    Contributor

    We hit this in a production Windows app (Otzaria, Flutter 3.47.2) as "clicking in a SelectionArea extends the previous selection, as if Shift were held" (Otzaria/otzaria#1645). Here is a deterministic repro and the exact code path, which I think confirms @yuuuuuzj's extended-flag theory.

    Root cause

    KeyboardKeyEmbedderHandler::GetPhysicalKey normalizes scancode | (extended ? 0xE000 : 0) and falls back to windowsPlane | scancode when the result isn't in windowsToPhysicalMap_. So a VK_SHIFT message with the extended bit set (0xE036, 0xE02A) or with scancode 0 is recorded under a non-standard physical key (0x1600000036, 0x1600000000), while its logical key is still Shift.

    After that, the key can never be released:

    • A normal Shift up arrives with the standard scancode, so it resolves to the standard physical key. There is no record for it, and it is dropped ("The physical key has been released before…").
    • SyncModifiersIfNeeded (MK_SHIFT on WM_MOUSEMOVE) and SynchronizeCriticalPressedStates (GetKeyState(VK_LSHIFT/VK_RSHIFT)) only check the records of physical_shift_left / physical_shift_right. They never see the plane key.
    • For scancode 0, ResolveKeyCode also returns MapVirtualKey(0, MAPVK_VSC_TO_VK_EX) == 0.

    So HardwareKeyboard.isShiftPressed stays true for good. This matches the 0x1600000036 value in the log above.

    Deterministic repro (no IME needed)

    Run flutter create on Windows, log HardwareKeyboard.instance.physicalKeysPressed every 100 ms, then PostMessage to the FLUTTERVIEW child HWND:

    WM_KEYDOWN  VK_SHIFT  lParam = 0x01360001   // scancode 0x36 + extended bit
    WM_KEYUP    VK_SHIFT  lParam = 0xC0360001   // normal up
    WM_MOUSEMOVE 0        (no MK_SHIFT)
    

    Result: shift=true physical=1600000036 after all three messages. With a down of lParam = 0x00000001 (scancode 0) followed by a normal up, the key 0x1600000000 is added and also stays stuck.

    Real input through SendInput (left/right Shift, Shift + gray arrows, Shift + numpad with NumLock on, VK_SHIFT injected with scancode 0 or KEYEVENTF_EXTENDEDKEY) did not get stuck on my machine. So the trigger in the wild is a Shift message whose scancode or extended flag doesn't match the OS key state. IMEs, key remappers and remote-control tools are the likely sources. Once such a message arrives, nothing in the engine can recover from it.

    Workaround that confirms the diagnosis

    A SetWindowSubclass on the view HWND rewrites VK_SHIFT key messages to the canonical scancode (0x36 stays right, anything else becomes 0x2A) and clears the extended bit. With it, the PostMessage repro above releases correctly, and real input behaves identically: Otzaria/otzaria#1706.

    An engine-side fix would be to apply the same normalization for VK_SHIFT in GetPhysicalKey / ResolveKeyCode. An alternative is to have SynthesizeIfNeeded also release any record whose logical key is Shift.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2a: text inputplatform-windowsteam-windowstriaged-windows

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions