Repository navigation
Description
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:
- Focus on a TextField widget and write something
- 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
- 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
- Modifier keys state should also be synchronized based on pointer events #115066
- [windows] Pressing Right-Shift turns on caps lock and locks in a TextField #75675
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
[-][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[/+]saurabh-mirajkar commentedon Feb 17, 2026
@adrianflutur Thanks for the report.
yuuuuuzj commentedon Jun 3, 2026
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.
yuuuuuzj commentedon Jun 9, 2026
{
"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?
yuuuuuzj commentedon Jun 29, 2026
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.
adrianflutur commentedon Jul 8, 2026
Hey @yuuuuuzj, sorry for the delay. I've seen your message but now it seems to be deleted.
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.
yuuuuuzj commentedon Jul 16, 2026
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.
fix(windows): Shift が押しっぱなし扱いで残りホイールが横スクロールしかしなくなる問題を修正
palmoni5 commentedon Oct 1, 2026
We hit this in a production Windows app (Otzaria, Flutter 3.47.2) as "clicking in a
SelectionAreaextends 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::GetPhysicalKeynormalizesscancode | (extended ? 0xE000 : 0)and falls back towindowsPlane | scancodewhen the result isn't inwindowsToPhysicalMap_. So aVK_SHIFTmessage with the extended bit set (0xE036,0xE02A) or with scancode0is recorded under a non-standard physical key (0x1600000036,0x1600000000), while its logical key is still Shift.After that, the key can never be released:
SyncModifiersIfNeeded(MK_SHIFTonWM_MOUSEMOVE) andSynchronizeCriticalPressedStates(GetKeyState(VK_LSHIFT/VK_RSHIFT)) only check the records ofphysical_shift_left/physical_shift_right. They never see the plane key.ResolveKeyCodealso returnsMapVirtualKey(0, MAPVK_VSC_TO_VK_EX) == 0.So
HardwareKeyboard.isShiftPressedstaystruefor good. This matches the0x1600000036value in the log above.Deterministic repro (no IME needed)
Run
flutter createon Windows, logHardwareKeyboard.instance.physicalKeysPressedevery 100 ms, thenPostMessageto theFLUTTERVIEWchild HWND:Result:
shift=true physical=1600000036after all three messages. With a down oflParam = 0x00000001(scancode 0) followed by a normal up, the key0x1600000000is added and also stays stuck.Real input through
SendInput(left/right Shift, Shift + gray arrows, Shift + numpad with NumLock on,VK_SHIFTinjected with scancode 0 orKEYEVENTF_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
SetWindowSubclasson the view HWND rewritesVK_SHIFTkey messages to the canonical scancode (0x36stays right, anything else becomes0x2A) 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_SHIFTinGetPhysicalKey/ResolveKeyCode. An alternative is to haveSynthesizeIfNeededalso release any record whose logical key is Shift.[Windows] Normalize Shift key messages with a non-standard scan code
[Windows] Normalize Shift key messages with a non-standard scan code
Windows: נרמול הודעות Shift חריגות לפני ה-engine (issue Otzaria#1645)
[Windows] Normalize Shift key messages with a non-standard scan code
[Windows] Normalize Shift key messages with a non-standard scan code
[Windows] Normalize Shift key messages with a non-standard scan code (f…