Repository: flutter
Issue: [Windows] Keyboard shortcuts stop working after modifier key repeat
Labels: a: text input,framework,platform-windows,P2,team-framework,triaged-framework

## Steps to Reproduce

1. Execute `flutter run` on the code sample
2. Type some text with spaces, press Ctrl+Z to undo (works OK)
3. Press any modifier key (e.g. Ctrl) or a combination of modifier keys (e.g. Shift + Win) and hold for a short while
4. Press arrow keys to move around text, Ctrl+Z again to undo more edits and other shortcuts

**Expected results:** Keyboard shortcuts work
**Actual results:** Shortcuts stop working and the following errors are shown in debug mode:

<details>
<summary>Errors</summary>

```
Launching lib\main.dart on Windows in debug mode...
Connecting to VM Service at ws://127.0.0.1:64705/23jNOxPBevw=/ws
Unable to parse JSON message:
The document is empty.

════════ Exception caught by services library ══════════════════════════════════
The following assertion was thrown during a platform message callback:
A KeyRepeatEvent is dispatched, but the state shows that the physical key is not pressed. If this occurs in real application, please report this bug to Flutter. If this occurs in unit tests, please ensure that simulated events follow Flutter's event model as documented in `HardwareKeyboard`. This was the event: KeyRepeatEvent#abbd4(physicalKey: PhysicalKeyboardKey#700e1(usbHidUsage: "0x000700e1", debugName: "Shift Left"), logicalKey: LogicalKeyboardKey#00102(keyId: "0x200000102", keyLabel: "Shift Left", debugName: "Shift Left"), character: null, timeStamp: 1:38:37.101324)
'package:flutter/src/services/hardware_keyboard.dart':
Failed assertion: line 425 pos 16: '_pressedKeys.containsKey(event.physicalKey)'


Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=2_bug.md

When the exception was thrown, this was the stack
#2      HardwareKeyboard._assertEventIsRegular.<anonymous closure>
#3      HardwareKeyboard._assertEventIsRegular
#4      HardwareKeyboard.handleKeyEvent
#5      KeyEventManager.handleRawKeyMessage
#6      BasicMessageChannel.setMessageHandler.<anonymous closure>
#7      _DefaultBinaryMessenger.setMessageHandler.<anonymous closure>
#8      _invoke2 (dart:ui/hooks.dart:186:13)
#9      _ChannelCallbackRecord.invoke (dart:ui/channel_buffers.dart:42:5)
#10     _Channel.push (dart:ui/channel_buffers.dart:132:31)
#11     ChannelBuffers.push (dart:ui/channel_buffers.dart:329:17)
#12     PlatformDispatcher._dispatchPlatformMessage (dart:ui/platform_dispatcher.dart:599:22)
#13     _dispatchPlatformMessage (dart:ui/hooks.dart:89:31)
(elided 2 frames from class _AssertionError)
════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by services library ══════════════════════════════════
A KeyRepeatEvent is dispatched, but the state shows that the physical key is not pressed. If this occurs in real application, please report this bug to Flutter. If this occurs in unit tests, please ensure that simulated events follow Flutter's event model as documented in `HardwareKeyboard`. This was the event: KeyRepeatEvent#abbd4(physicalKey: PhysicalKeyboardKey#700e1(usbHidUsage: "0x000700e1", debugName: "Shift Left"), logicalKey: LogicalKeyboardKey#00102(keyId: "0x200000102", keyLabel: "Shift Left", debugName: "Shift Left"), character: null, timeStamp: 1:38:37.101324)
'package:flutter/src/services/hardware_keyboard.dart':
Failed assertion: line 425 pos 16: '_pressedKeys.containsKey(event.physicalKey)'

════════════════════════════════════════════════════════════════════════════════
Unable to parse JSON message:
The document is empty.
Unable to parse JSON message:
The document is empty.

════════ Exception caught by services library ══════════════════════════════════
A KeyRepeatEvent is dispatched, but the state shows that the physical key is not pressed. If this occurs in real application, please report this bug to Flutter. If this occurs in unit tests, please ensure that simulated events follow Flutter's event model as documented in `HardwareKeyboard`. This was the event: KeyRepeatEvent#abbd4(physicalKey: PhysicalKeyboardKey#700e1(usbHidUsage: "0x000700e1", debugName: "Shift Left"), logicalKey: LogicalKeyboardKey#00102(keyId: "0x200000102", keyLabel: "Shift Left", debugName: "Shift Left"), character: null, timeStamp: 1:38:37.101324)
'package:flutter/src/services/hardware_keyboard.dart':
Failed assertion: line 425 pos 16: '_pressedKeys.containsKey(event.physicalKey)'

════════════════════════════════════════════════════════════════════════════════
Unable to parse JSON message:
The document is empty.

════════ Exception caught by services library ══════════════════════════════════
A KeyRepeatEvent is dispatched, but the state shows that the physical key is not pressed. If this occurs in real application, please report this bug to Flutter. If this occurs in unit tests, please ensure that simulated events follow Flutter's event model as documented in `HardwareKeyboard`. This was the event: KeyRepeatEvent#abbd4(physicalKey: PhysicalKeyboardKey#700e1(usbHidUsage: "0x000700e1", debugName: "Shift Left"), logicalKey: LogicalKeyboardKey#00102(keyId: "0x200000102", keyLabel: "Shift Left", debugName: "Shift Left"), character: null, timeStamp: 1:38:37.101324)
'package:flutter/src/services/hardware_keyboard.dart':
Failed assertion: line 425 pos 16: '_pressedKeys.containsKey(event.physicalKey)'

════════════════════════════════════════════════════════════════════════════════
Unable to parse JSON message:
The document is empty.

════════ Exception caught by services library ══════════════════════════════════
A KeyRepeatEvent is dispatched, but the state shows that the physical key is not pressed. If this occurs in real application, please report this bug to Flutter. If this occurs in unit tests, please ensure that simulated events follow Flutter's event model as documented in `HardwareKeyboard`. This was the event: KeyRepeatEvent#abbd4(physicalKey: PhysicalKeyboardKey#700e1(usbHidUsage: "0x000700e1", debugName: "Shift Left"), logicalKey: LogicalKeyboardKey#00102(keyId: "0x200000102", keyLabel: "Shift Left", debugName: "Shift Left"), character: null, timeStamp: 1:38:37.101324)
'package:flutter/src/services/hardware_keyboard.dart':
Failed assertion: line 425 pos 16: '_pressedKeys.containsKey(event.physicalKey)'

════════════════════════════════════════════════════════════════════════════════
Unable to parse JSON message:
The document is empty.

════════ Exception caught by services library ══════════════════════════════════
A KeyRepeatEvent is dispatched, but the state shows that the physical key is not pressed. If this occurs in real application, please report this bug to Flutter. If this occurs in unit tests, please ensure that simulated events follow Flutter's event model as documented in `HardwareKeyboard`. This was the event: KeyRepeatEvent#abbd4(physicalKey: PhysicalKeyboardKey#700e1(usbHidUsage: "0x000700e1", debugName: "Shift Left"), logicalKey: LogicalKeyboardKey#00102(keyId: "0x200000102", keyLabel: "Shift Left", debugName: "Shift Left"), character: null, timeStamp: 1:38:37.101324)
'package:flutter/src/services/hardware_keyboard.dart':
Failed assertion: line 425 pos 16: '_pressedKeys.containsKey(event.physicalKey)'

════════════════════════════════════════════════════════════════════════════════
Unable to parse JSON message:
The document is empty.

════════ Exception caught by services library ══════════════════════════════════
A KeyRepeatEvent is dispatched, but the state shows that the physical key is not pressed. If this occurs in real application, please report this bug to Flutter. If this occurs in unit tests, please ensure that simulated events follow Flutter's event model as documented in `HardwareKeyboard`. This was the event: KeyRepeatEvent#abbd4(physicalKey: PhysicalKeyboardKey#700e1(usbHidUsage: "0x000700e1", debugName: "Shift Left"), logicalKey: LogicalKeyboardKey#00102(keyId: "0x200000102", keyLabel: "Shift Left", debugName: "Shift Left"), character: null, timeStamp: 1:38:37.101324)
'package:flutter/src/services/hardware_keyboard.dart':
Failed assertion: line 425 pos 16: '_pressedKeys.containsKey(event.physicalKey)'

════════════════════════════════════════════════════════════════════════════════
Unable to parse JSON message:
The document is empty.

════════ Exception caught by services library ══════════════════════════════════
A KeyRepeatEvent is dispatched, but the state shows that the physical key is not pressed. If this occurs in real application, please report this bug to Flutter. If this occurs in unit tests, please ensure that simulated events follow Flutter's event model as documented in `HardwareKeyboard`. This was the event: KeyRepeatEvent#abbd4(physicalKey: PhysicalKeyboardKey#700e1(usbHidUsage: "0x000700e1", debugName: "Shift Left"), logicalKey: LogicalKeyboardKey#00102(keyId: "0x200000102", keyLabel: "Shift Left", debugName: "Shift Left"), character: null, timeStamp: 1:38:37.101324)
'package:flutter/src/services/hardware_keyboard.dart':
Failed assertion: line 425 pos 16: '_pressedKeys.containsKey(event.physicalKey)'



[...]



════════ Exception caught by services library ══════════════════════════════════
A KeyRepeatEvent is dispatched, but the state shows that the physical key is not pressed. If this occurs in real application, please report this bug to Flutter. If this occurs in unit tests, please ensure that simulated events follow Flutter's event model as documented in `HardwareKeyboard`. This was the event: KeyRepeatEvent#abbd4(physicalKey: PhysicalKeyboardKey#700e1(usbHidUsage: "0x000700e1", debugName: "Shift Left"), logicalKey: LogicalKeyboardKey#00102(keyId: "0x200000102", keyLabel: "Shift Left", debugName: "Shift Left"), character: null, timeStamp: 1:38:37.101324)
'package:flutter/src/services/hardware_keyboard.dart':
Failed assertion: line 425 pos 16: '_pressedKeys.containsKey(event.physicalKey)'

════════════════════════════════════════════════════════════════════════════════
Unable to parse JSON message:
The document is empty.

════════ Exception caught by services library ══════════════════════════════════
A KeyRepeatEvent is dispatched, but the state shows that the physical key is not pressed. If this occurs in real application, please report this bug to Flutter. If this occurs in unit tests, please ensure that simulated events follow Flutter's event model as documented in `HardwareKeyboard`. This was the event: KeyRepeatEvent#abbd4(physicalKey: PhysicalKeyboardKey#700e1(usbHidUsage: "0x000700e1", debugName: "Shift Left"), logicalKey: LogicalKeyboardKey#00102(keyId: "0x200000102", keyLabel: "Shift Left", debugName: "Shift Left"), character: null, timeStamp: 1:38:37.101324)
'package:flutter/src/services/hardware_keyboard.dart':
Failed assertion: line 425 pos 16: '_pressedKeys.containsKey(event.physicalKey)'

════════════════════════════════════════════════════════════════════════════════

```

</details>

<details>
<summary>Code sample</summary>

```dart
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(
      title: 'Flutter Demo',
      theme: ThemeData(primarySwatch: Colors.blue),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text(widget.title)),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: const <Widget>[
            Text('Type stuff below'),
            Expanded(
              child: TextField(maxLines: null),
            ),
          ],
        ),
      ),
    );
  }
}
```

</details>

<details>
  <summary>Logs</summary>

```
> flutter doctor -v
[√] Flutter (Channel master, 3.1.0-0.0.pre.1354, on Microsoft Windows [Version 10.0.19044.1708], locale en-US)
    • Flutter version 3.1.0-0.0.pre.1354 on channel master at C:\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision a30012b275 (9 hours ago), 2022-06-22 17:04:07 -0700
    • Engine revision fc08bf45b0
    • Dart version 2.18.0 (build 2.18.0-216.0.dev)
    • DevTools version 2.14.0

[X] Android toolchain - develop for Android devices
    X 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/docs/get-started/install/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
    • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.11.15)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
    • Visual Studio Community 2019 version 16.11.32510.428
    • Windows 10 SDK version 10.0.19041.0

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/windows#android-setup for detailed instructions).

[√] VS Code, 64-bit edition (version 1.68.1)
    • VS Code at C:\Program Files\Microsoft VS Code
    • Flutter extension version 3.42.0

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.19044.1708]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 102.0.5005.115
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 101.0.1210.39

[√] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 2 categories.
```

</details>