Repository navigation
[Windows] HardwareKeyboard misses next key press after alt is pressed #177822
Copy link
Copy link
Closed
Copy link
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: desktopRunning on desktopRunning on desktopengineflutter/engine related. See also e: labels.flutter/engine related. See also e: labels.platform-windowsBuilding on or for Windows specificallyBuilding on or for Windows specificallyr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-windowsOwned by the Windows platform teamOwned by the Windows platform teamtriaged-windowsTriaged by the Windows platform teamTriaged by the Windows platform team
Description
Steps to reproduce
These steps use Windows 11 with Flutter 3.35.7 (see doctor output below).
- Create a new Flutter project with
flutter create - In
main.dart, add the following inmain()afterrunApp():HardwareKeyboard.instance.addHandler((event) { if (event is KeyDownEvent) { print('Key pressed: ${event.logicalKey.debugName}'); } return false; });
- Run the project
- Try the following two things:
- Press the left alt key 4 times
- Press alt, then release alt, then press another key
Expected results
I expect an output like the following:
(for the first)
Key pressed: Alt Left
Key pressed: Alt Left
Key pressed: Alt Left
Key pressed: Alt Left
(for the second)
Key pressed: Alt Left
Key pressed: Key A
Actual results
Instead, I get the following output:
(for the first)
Key pressed: Alt Left
Key pressed: Alt Left
(for the second)
Key pressed: Alt Left
Note that this does not happen for other keys, including other modifiers like shift and control.
Code sample
Code sample
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() {
runApp(const MyApp());
HardwareKeyboard.instance.addHandler((event) {
if (event is KeyDownEvent) {
print('Key pressed: ${event.logicalKey.debugName}');
}
return false;
});
}
// Rest of file unchanged from flutter create outputFlutter Doctor output
Doctor output
[✓] Flutter (Channel stable, 3.35.7, on Microsoft Windows [Version 10.0.26200.6899], locale en-US) [411ms]
• Flutter version 3.35.7 on channel stable at C:\Users\qbgee\Documents\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision adc9010625 (9 days ago), 2025-10-21 14:16:03 -0400
• Engine revision 035316565a
• Dart version 3.9.2
• DevTools version 2.48.0
• Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop,
enable-android, enable-ios, cli-animations, enable-lldb-debugging
[✓] Windows Version (11 Home 64-bit, 25H2, 2009) [1,943ms]
[✗] Android toolchain - develop for Android devices [161ms]
✗ Unable to locate Android SDK.
Install Android Studio from: https://developer.android.com/studio/index.html
On first launch it will assist you in installing the Android SDK components.
(or visit https://flutter.dev/to/windows-android-setup for detailed instructions).
If the Android SDK has been installed to a custom location, please use
`flutter config --android-sdk` to update to that location.
[✓] Chrome - develop for the web [118ms]
• Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
[✓] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.14.10) [116ms]
• Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
• Visual Studio Community 2022 version 17.14.36327.8
• Windows 10 SDK version 10.0.26100.0
[!] Android Studio (not installed) [12ms]
• Android Studio not found; download from https://developer.android.com/studio/index.html
(or visit https://flutter.dev/to/windows-android-setup for detailed instructions).
[✓] VS Code (version 1.105.1) [11ms]
• VS Code at C:\Users\qbgee\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.120.0
[✓] Connected device (3 available) [194ms]
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.26200.6899]
• Chrome (web) • chrome • web-javascript • Google Chrome 141.0.7390.123
• Edge (web) • edge • web-javascript • Microsoft Edge 141.0.3537.99
[✓] Network resources [222ms]
• All expected network resources are available.
! Doctor found issues in 2 categories.Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: desktopRunning on desktopRunning on desktopengineflutter/engine related. See also e: labels.flutter/engine related. See also e: labels.platform-windowsBuilding on or for Windows specificallyBuilding on or for Windows specificallyr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-windowsOwned by the Windows platform teamOwned by the Windows platform teamtriaged-windowsTriaged by the Windows platform teamTriaged by the Windows platform team
Activity
[-][Windows] HardwareKeyboard skips every other key press from the alt key[/-][+][Windows] HardwareKeyboard misses every other key press from the alt key[/+]tirth-patel-nc commentedon Oct 31, 2025
@josh-audio thanks for the report. I can't seem to replicate the reported issue. I tested on 3.35.7 and latest master on macOS.
Screen.Recording.2025-10-31.at.4.56.35.PM.mov
could you please check if you can still reproduce this on the latest master? (also share the verbose logs with flutter run -v) also, are there any console errors similar to #107972?
josh-audio commentedon Oct 31, 2025
Hi @tirth-patel-nc, thank you for looking into this!
My apologies, I missed an important detail in the report. I also cannot reproduce this when running on web with e.g.
-p chrome- it only reproduces on a Windows-native build for me. So, I am wondering if this is related to the Windows platform embedder.To answer your questions:
flutter channel masterand thenflutter run -d windows, I still observe this behavior. See the video below.I have a Linux desktop as well, so I will test it there when I get a chance.
Recording.2025-10-31.103912.mp4
[-][Windows] HardwareKeyboard misses every other key press from the alt key[/-][+][Windows] HardwareKeyboard misses next key press after alt is pressed[/+]josh-audio commentedon Oct 31, 2025
My motivating case for this is for a complex editor, where modifier keys including alt are used to change the current mouse action. Examples include:
For this use-case, my alt-modified mouse actions were showing the behavior I originally reported here.
After testing this morning, I've realized that the issue is a bit simpler: If "alt" is pressed and released, Flutter will miss the next keystroke. I have modified the report to reflect this.
If I press and release "alt", "a", "b", and "c" in that order, I get the following output:
I've tried checking if it does anything when I press and release "alt", then press another key. I've tried a lot of combinations, but so far I can't find any functionality tied to this behavior, though it does play a Windows error sound when I press the second key.
josh-audio commentedon Oct 31, 2025
Looks like the error sound is already reported: #119251
I see a workaround in that issue for this specific case (press alt, release alt, press key), but no mention of losing the key press. I can't try it now, but I will try it as soon as I can and report here.
josh-audio commentedon Oct 31, 2025
Just tried it, and it addressed the problem for me.
I added the following case to
FlutterWindow::MessageHandler()influtter_window.cpp:The full file is below.
flutter_window.cpp
FusoraTech commentedon Nov 1, 2025
Mac, Windows and Linux need to implement "menus". Menu items on Windows react as a combination of Alt+Key (Accelerator), or Alt alone, bringing focus to the menu, and another action key after. This seems linked to some kind of key press consumption from some menu engine. I think it needs analysis from @mattkae and how window menus are being implemented in the new windowing system.
josh-audio commentedon Nov 2, 2025
The workaround above has at least one major drawback so far. If I press alt + tab to switch to another application, then use the mouse to put the application back in focus,
HardwareKeyboard.instance.isAltPressedwill be true until I press alt again.I can work around this using a plugin (specifically https://pub.dev/packages/window_manager), but it's quite involved; essentially:
HardwareKeyboardthat listens for alt, ctrl, and shift, and records the current pressed state in my own custom singleton storeWindowListener.onWindowBlur()fromwindow_managerto reset these values when the window loses focustirth-patel-nc commentedon Nov 3, 2025
@josh-audio thanks for the detailed comments. I'll keep this open for team input and tracking.
1 remaining item
mattkae commentedon Nov 13, 2025
I've been looking into this today. It looks like consuming the
WM_SYSKEYDOWN (VK_MENU)message is the way to go, but I am seeing that it affects alt tab. I should be able to work around this, but I'll have to think about it a bit more :)As for the multi-window work: we should provide a hook in the API for users to do handle this when asked to do so by the embedder. This shouldn't be too difficult to add in my opinion, and we can do the interception of the message in the meantime.
Fix for win32 embedder failing to send all alt key downs to the flutt…
Reverts "Fix for win32 embedder failing to send all alt key downs to …
Fix for win32 embedder failing to send all alt key downs to the flutt…
Reverts "Fix for win32 embedder failing to send all alt key downs to …
Fix for win32 embedder failing to send all alt key downs to the flutt…
Reverts "Fix for win32 embedder failing to send all alt key downs to …
github-actions commentedon Dec 10, 2025
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.