Skip to content

[macOS] Bogus keys reported in RawKeyboard.instance.keysPressed #75627

Description

@tgucio

Steps to Reproduce

  1. Run flutter create editable_text_keys.
  2. Update main.dart as follows:
import 'package:flutter/services.dart';
import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'EditableText keys test',
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key}) : super(key: key);

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  TextEditingController _textController;
  FocusNode _focusNode;

  @override
  void initState() {
    super.initState();
    _textController = TextEditingController(text: 'some\nmulti\nline\ntext\n\njust\na few\nlines\nmore\n...\n...\n');
    _focusNode = FocusNode(
      onKey: (_, RawKeyEvent keyEvent) {
        if (keyEvent is! RawKeyDownEvent) return false;
        final Set<LogicalKeyboardKey> keysPressed = LogicalKeyboardKey.collapseSynonyms(RawKeyboard.instance.keysPressed);
        print('FocusNode onKey RawKeyEvent: $keyEvent | keysPressed: $keysPressed');
        return false;
      }
    );
  }

  @override
  void dispose() {
    _focusNode.dispose();
    _textController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('EditableText keys test')),
      body: Container(
        margin: EdgeInsets.all(10.0),
        child: EditableText(
          controller: _textController,
          focusNode: _focusNode,
          maxLines: null,
          autofocus: true,
          style: TextStyle(fontSize: 24.0, color: Colors.black),
          cursorColor: Colors.amber,
          backgroundCursorColor: Colors.grey,
        ),
      ),
    );
  }
}
  1. Run the application on macOS. Press different keys, including arrow keys and observe in the printed logs if the RawKeyEvent and keysPressed match what's being pressed.
  2. Switch to other applications. Then switch to a Chrome browser window. Navigate to a page with text input, enter some text, select all using Command+A, cut text using Command+X.
  3. Switch back to the Flutter app window and repeat step 3.

Expected results: Only the actual keys being pressed are reported in the RawKeyboard.instance.keysPressed set.

[+3072 ms] flutter: FocusNode onKey RawKeyEvent: RawKeyDownEvent#a196a(logicalKey: LogicalKeyboardKey#70050(keyId: "0x100070050", keyLabel: "", debugName: "Arrow
Left"), physicalKey: PhysicalKeyboardKey#70050(usbHidUsage: "0x00070050", debugName: "Arrow Left")) | keysPressed: {LogicalKeyboardKey#70050(keyId: "0x100070050",
keyLabel: "", debugName: "Arrow Left")}

Actual results: Sometimes, after a while, a bogus key 'A' is constantly reported in RawKeyboard.instance.keysPressed alongside the arrow keys pressed:

[+4243 ms] flutter: FocusNode onKey RawKeyEvent: RawKeyDownEvent#54d29(logicalKey: LogicalKeyboardKey#70050(keyId: "0x100070050", keyLabel: "", debugName: "Arrow
Left"), physicalKey: PhysicalKeyboardKey#70050(usbHidUsage: "0x00070050", debugName: "Arrow Left")) | keysPressed: {LogicalKeyboardKey#70004(keyId: "0x100070004",
keyLabel: "Key A", debugName: "Key A"), LogicalKeyboardKey#70050(keyId: "0x100070050", keyLabel: "", debugName: "Arrow Left")}
Logs
"flutter -run verbose" output too long - will attach as render_editable_keys_run_verbose_output.txt.
% flutter analyze      
Analyzing editable_text_keys...                                         
No issues found! (ran in 3.7s)
% flutter doctor -v    
[✓] Flutter (Channel master, 1.26.0-18.0.pre.212, on Mac OS X 10.15.7 19H114 darwin-x64, locale en-GB)
    • Flutter version 1.26.0-18.0.pre.212 at /Library/Frameworks/flutter
    • Framework revision 02d441ea55 (3 days ago), 2021-02-05 17:17:12 -0800
    • Engine revision b04955656c
    • Dart version 2.13.0 (build 2.13.0-0.0.dev)

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /Users/tgucio/Library/Android/sdk
    • Platform android-30, build-tools 30.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.3, Build version 12C33
    • CocoaPods version 1.10.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    • 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 1.8.0_242-release-1644-b3-6915495)

[✓] VS Code (version 1.53.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.19.0

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-x64     • Mac OS X 10.15.7 19H114 darwin-x64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 88.0.4324.146

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: desktopRunning on desktopa: text inputEntering text in a text field or keyboard related problemsengineflutter/engine related. See also e: labels.platform-macosBuilding on or for macOS specificallywaiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions