Repository: flutter
Issue: HardwareKeyboard logicalKeysPressed returns previously pressed keys
Labels: a: text input,framework,a: desktop,has reproducible steps,P2,found in release: 2.8,found in release: 2.9,team-text-input,triaged-text-input

`HardwareKeyboard.instance.logicalKeysPressed` returns keys that was previously pressed instead of only the currently pressed key. Happens when pressing the meta key in addition to other keys, on Mac OS.

## Steps to Reproduce

1. flutter create --platforms web foo
2. Put attached code sample in lib/main.dart
3. flutter run -d chrome -t lib/main.dart
2. Open page in chrome
3. Press keys `cmd + k` and release
4. Press key `arrow left` and release
5. Check console output
6. See that the last keypress includes the key `k` when only the `arrow left` key was pressed

**Expected results:**
```
LogicalKeySet#4b191(keys: Meta Left)
LogicalKeySet#5c7f7(keys: Meta Left + Key K)
LogicalKeySet#6c398(keys: Arrow Left)
```

**Actual results:**
```
LogicalKeySet#4b191(keys: Meta Left)
LogicalKeySet#5c7f7(keys: Meta Left + Key K)
LogicalKeySet#6c398(keys: Arrow Left + Key K)
```

<details>
<summary>Code sample</summary>

```dart
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: GlobalKeyboardListener(
        onKeyEvent: (KeyEvent event) {
          if (event is KeyDownEvent) {
            if (HardwareKeyboard.instance.logicalKeysPressed.isNotEmpty) {
              final pressedKeys = LogicalKeySet.fromSet(
                HardwareKeyboard.instance.logicalKeysPressed,
              );

              // ignore: avoid_print
              print(pressedKeys);
            }
          }
          return false;
        },
        child: const Text("hello"),
      ),
    );
  }
}

class GlobalKeyboardListener extends StatefulWidget {
  final bool Function(KeyEvent keyEvent) onKeyEvent;
  final Widget child;

  const GlobalKeyboardListener({
    required this.onKeyEvent,
    required this.child,
    Key? key,
  }) : super(key: key);

  @override
  State<GlobalKeyboardListener> createState() {
    return _GlobalKeyboardListenerState();
  }
}

class _GlobalKeyboardListenerState<T> extends State<GlobalKeyboardListener> {
  @override
  void initState() {
    startListen();
    super.initState();
  }

  @override
  void dispose() {
    stopListen();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return widget.child;
  }

  void startListen() {
    HardwareKeyboard.instance.addHandler(widget.onKeyEvent);
  }

  void stopListen() {
    HardwareKeyboard.instance.removeHandler(widget.onKeyEvent);
  }
}
```

</details>

<details>
  <summary>Logs</summary>

```
Analyzing foo...
No issues found! (ran in 1.3s)
```

```
$ flutter doctor -v
[✓] Flutter (Channel stable, 2.8.0, on macOS 12.0.1 21A559 darwin-x64, locale en-GB)
    • Flutter version 2.8.0 at /usr/local/Caskroom/flutter/2.2.1/flutter
    • Upstream repository git@github.com:flutter/flutter.git
    • Framework revision cf44000065 (13 days ago), 2021-12-08 14:06:50 -0800
    • Engine revision 40a99c5951
    • Dart version 2.15.0

[✗] Android toolchain - develop for Android devices
    ✗ 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/macos#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.


[!] Xcode - develop for iOS and macOS (Xcode 13.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    ✗ CocoaPods not installed.
        CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/platform-plugins
      To install see https://guides.cocoapods.org/using/getting-started.html#installation for instructions.

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[!] 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/macos#android-setup for detailed instructions).

[✓] VS Code (version 1.63.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.29.0

[✓] Connected device (1 available)
    • Chrome (web) • chrome • web-javascript • Google Chrome 96.0.4664.110

! Doctor found issues in 3 categories.
```

</details>