Skip to content

[Web] RawKeyboardListener does not return correct data #35347

Open

Description

@mjeffw

Steps to Reproduce

Gist of code to reproduce the problem:
https://gist.github.com/mjeffw/8f3f57d23b596fde3c1a8dac93a64549

  1. Create a flutter web app with a TextField wrapped by a RawKeyboardListener
  2. In the onKey callback, check for a specific key using the following code: if (value.logicalKey == LogicalKeyboardKey.keyA) print('A');
  3. Run the web app and type the expected key. It never matches.

If I print the logicalKey value of the RawKeyEvent, and type the letter 'A', here is the output:

dart_sdk.js:18740 LogicalKeyboardKey#00039(keyId: "0x00000039", keyLabel: "9", debugName: "Digit 9")
dart_sdk.js:18740 LogicalKeyboardKey#f1dc1(keyId: "0x1000c018a", keyLabel: null, debugName: "Launch Mail")
dart_sdk.js:18740 LogicalKeyboardKey#f1dc1(keyId: "0x1000c018a", keyLabel: null, debugName: "Launch Mail")
dart_sdk.js:18740 LogicalKeyboardKey#00039(keyId: "0x00000039", keyLabel: "9", debugName: "Digit 9")

Logs

Jeffs-MacBook-Pro-2:flutter_web_rawkeyboardlistener_example jeff$ webdev serve --verbose
[INFO] Connecting to the build daemon...
[INFO] Generating build script...
[INFO] Generating build script completed, took 401ms
[INFO] 
[INFO] Starting daemon...
[INFO]BuildDefinition: Initializing inputs
[INFO]BuildDefinition: Reading cached asset graph...
[WARNING]BuildDefinition: Throwing away cached asset graph due to Dart SDK update.
[INFO]BuildDefinition: Cleaning up outputs from previous builds....
[INFO]BuildDefinition: Cleaning up outputs from previous builds. completed, took 136ms

[INFO] Generating build script...
[INFO] Generating build script completed, took 109ms
[INFO] 
[INFO] Creating build script snapshot......
[INFO] Creating build script snapshot... completed, took 12.4s
[INFO] 
[INFO] Starting daemon...
[INFO]BuildDefinition: Initializing inputs
[INFO]BuildDefinition: Building new asset graph...
[INFO]BuildDefinition: Building new asset graph completed, took 1.5s

[INFO]BuildDefinition: Checking for unexpected pre-existing outputs....
[INFO]BuildDefinition: Checking for unexpected pre-existing outputs. completed, took 2ms

[INFO] Initializing inputs
[INFO] Building new asset graph...
[INFO] Building new asset graph completed, took 1.5s
[INFO] 
[INFO] Checking for unexpected pre-existing outputs....
[INFO] Checking for unexpected pre-existing outputs. completed, took 2ms
[INFO] 
[INFO] Setting up file watchers...
[INFO] Setting up file watchers completed, took 4ms
[INFO] 
[INFO] Registering build targets...
[INFO] Starting initial build...
[INFO] Starting resource servers...
[INFO] Serving `web` on http://127.0.0.1:8080

[INFO] About to build [web]...
[INFO]Build: Running build...
[INFO]Heartbeat: 1.0s elapsed, 89/108 actions completed.
[INFO]Heartbeat: 2.0s elapsed, 285/303 actions completed.
[INFO]Heartbeat: 3.1s elapsed, 517/537 actions completed.
[INFO]Heartbeat: 4.2s elapsed, 694/726 actions completed.
[INFO]Heartbeat: 5.3s elapsed, 694/726 actions completed.
[INFO]Heartbeat: 6.4s elapsed, 705/741 actions completed.
[INFO]Heartbeat: 7.4s elapsed, 716/750 actions completed.
[INFO]Heartbeat: 8.5s elapsed, 720/752 actions completed.
[INFO]Heartbeat: 9.5s elapsed, 722/752 actions completed.
[INFO]Heartbeat: 10.6s elapsed, 726/754 actions completed.
[INFO]Heartbeat: 11.6s elapsed, 731/754 actions completed.
[INFO]Heartbeat: 12.7s elapsed, 734/754 actions completed.
[INFO]Heartbeat: 13.8s elapsed, 737/754 actions completed.
[INFO]Heartbeat: 14.8s elapsed, 739/754 actions completed.
[INFO]Heartbeat: 15.8s elapsed, 740/754 actions completed.
[INFO]Heartbeat: 16.9s elapsed, 740/754 actions completed.
[INFO]Heartbeat: 17.9s elapsed, 742/754 actions completed.
[INFO]Heartbeat: 18.9s elapsed, 743/754 actions completed.
[INFO]Heartbeat: 20.0s elapsed, 744/754 actions completed.
[INFO]Heartbeat: 21.0s elapsed, 745/754 actions completed.
[INFO]Heartbeat: 22.1s elapsed, 748/754 actions completed.
[INFO]Heartbeat: 23.1s elapsed, 750/754 actions completed.
[INFO]Heartbeat: 24.2s elapsed, 750/754 actions completed.
[INFO]Heartbeat: 25.3s elapsed, 752/754 actions completed.
[INFO]Heartbeat: 26.3s elapsed, 752/754 actions completed.
[INFO]Heartbeat: 27.4s elapsed, 752/754 actions completed.
[INFO]Heartbeat: 28.4s elapsed, 752/754 actions completed.
[INFO]Heartbeat: 29.5s elapsed, 752/754 actions completed.
[INFO]Heartbeat: 30.5s elapsed, 754/754 actions completed.
[INFO]Build: Running build completed, took 30.9s

[INFO]Build: Caching finalized dependency graph...
[INFO]Build: Caching finalized dependency graph completed, took 197ms

[INFO]Build: Succeeded after 31.1s with 560 outputs (3266 actions)

[INFO] ----------------------------------------------------------------------------------------------------------------------------------------------------------------

[INFO] About to build [web]...
[INFO]Build: Updating asset graph...
[INFO]Build: Updating asset graph completed, took 12ms

[INFO]Build: Running build...
[INFO]Build: Running build completed, took 359ms

[INFO]Build: Caching finalized dependency graph...
[INFO]Build: Caching finalized dependency graph completed, took 242ms

[INFO]Build: Succeeded after 652ms with 9 outputs (7 actions)

[INFO] ----------------------------------------------------------------------------------------------------------------------------------------------------------------

flutter analyze
Analyzing flutter_web_rawkeyboardlistener_example...                    
No issues found! (ran in 2.8s)
Jeffs-MacBook-Pro-2:flutter_web_rawkeyboardlistener_example jeff$ flutter doctor -v
[✓] Flutter (Channel stable, v1.5.4-hotfix.2, on Mac OS X 10.14.5 18F132, locale en-US)
    • Flutter version 1.5.4-hotfix.2 at /Users/jeff/Projects/git/flutter
    • Framework revision 7a4c33425d (9 weeks ago), 2019-04-29 11:05:24 -0700
    • Engine revision 52c7a1e849
    • Dart version 2.3.0 (build 2.3.0-dev.0.5 a1668566e5)

 
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at /Users/jeff/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.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_152-release-1343-b01)
    • All Android licenses accepted.

[✓] iOS toolchain - develop for iOS devices (Xcode 10.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 10.2.1, Build version 10E1001
    • ios-deploy 1.9.4
    • CocoaPods version 1.6.1

[✓] Android Studio (version 3.4)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 35.3.1
    • Dart plugin version 183.6270
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)

[✓] IntelliJ IDEA Community Edition (version 2018.3.5)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • Flutter plugin version 33.4.2
    • Dart plugin version 183.5912.23

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

[!] Connected device
    ! No devices available

! Doctor found issues in 1 category.

Activity

  1. reopened this on Jul 1, 2019
  2. a-marenkov commented on Jul 11, 2019

    @a-marenkov

    @mjeffw try this workaround

          onKey: (RawKeyEvent value) {
            if (value.data is RawKeyEventDataAndroid) {
              final data = value.data as RawKeyEventDataAndroid;
              if (data.keyCode == KeyCode.TAB) {
                print('tab');
              }
              if (data.keyCode == KeyCode.A) {
                print('A');
              }
            }
          },
    
  3. added
    a: text inputEntering text in a text field or keyboard related problems
    on Jul 11, 2019
  4. added this to the milestone on Jul 11, 2019
  5. deckerst commented on Nov 13, 2019

    @deckerst
                  RawKeyboardListener(
                    focusNode: FocusNode(),
                    onKey: (RawKeyEvent event) => debugPrint('event=$event'),
                    child: TextField(),
                  ),

    This code used to work with v1.10.15, but since v1.10.16 the RawKeyboardListener does not receive the key events when the TextField is focused.

    In my case, I need to handle the up/down arrow keys. Is there a workaround?

  6. phamnhuvu-dev commented on Apr 19, 2020

    @phamnhuvu-dev

    same issue with @deckerst

  7. added
    P1High-priority issues at the top of the work list
    on May 29, 2020
  8. modified the milestone: on Jun 1, 2020
  9. Skquark commented on Jun 8, 2020

    @Skquark

    Was struggling with this bug too, it doesn't seem to fire RawKeyboardListener on web build. I've been futzing with it to use keyboard to control ScrollBar - ScrollView to bandaid bug here: #43694 but after our efforts, got stuck with this. Even tried the if (keyEvent.data is RawKeyEventDataWeb) part and researched the other issues regarding. Most of the bug reports were already closed like #33857 and #52656 but still should bump the issue.

  10. TahaTesser commented on Jun 16, 2020

    @TahaTesser
    Contributor

    @mjeffw
    Pressing a and tab

    Code Sample
    import 'package:flutter/material.dart';
    import 'package:flutter/services.dart';
    
    void main() => runApp(MyApp());
    
    class MyApp extends StatelessWidget {
      // This widget is the root of your application.
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Flutter Demo',
          theme: ThemeData(
            primarySwatch: Colors.blue,
          ),
          home: MyHomePage(title: 'Flutter Demo Home Page'),
        );
      }
    }
    
    class MyHomePage extends StatelessWidget {
      MyHomePage({Key key, this.title}) : super(key: key);
    
      final String title;
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text(title),
          ),
          body: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Text(
                  'Hello, World!',
                ),
                RawKeyboardListener(
                  child: TextField(
                    controller: TextEditingController(text: 'test'),
                  ),
                  focusNode: FocusNode(),
                  onKey: (RawKeyEvent value) {
                    print(value.logicalKey);
                    if (value.logicalKey == LogicalKeyboardKey.tab) print('tab');
                    if (value.logicalKey == LogicalKeyboardKey.keyA) print('A');
                  },
                ),
              ],
            ),
          ), // This trailing comma makes auto-formatting nicer for build methods.
        );
      }
    }
    
    
    LogicalKeyboardKey#00061(keyId: "0x00000061", keyLabel: "a", debugName: "Key A")
    A
    LogicalKeyboardKey#00061(keyId: "0x00000061", keyLabel: "a", debugName: "Key A")
    A
    LogicalKeyboardKey#63774(keyId: "0x10007002b", keyLabel: null, debugName: "Tab")
    tab
    LogicalKeyboardKey#63774(keyId: "0x10007002b", keyLabel: null, debugName: "Tab")
    tab
    
    
    flutter doctor -v
    [✓] Flutter (Channel dev, 1.20.0-0.0.pre, on Mac OS X 10.15.5 19F101, locale
        en-GB)
        • Flutter version 1.20.0-0.0.pre at /Users/tahatesser/Code/flutter_dev
        • Framework revision d9653445f4 (6 days ago), 2020-06-09 18:43:03 -0400
        • Engine revision e8c13aa012
        • Dart version 2.9.0 (build 2.9.0-14.0.dev 5c1376615e)
    
     
    [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.0)
        • Android SDK at /Users/tahatesser/Code/sdk
        • Platform android-30, build-tools 30.0.0
        • ANDROID_HOME = /Users/tahatesser/Code/sdk
        • 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-6222593)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 11.5)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Xcode 11.5, Build version 11E608c
        • CocoaPods version 1.9.3
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 4.0)
        • Android Studio at /Applications/Android Studio.app/Contents
        • Flutter plugin version 46.0.2
        • Dart plugin version 193.7361
        • Java version OpenJDK Runtime Environment (build
          1.8.0_242-release-1644-b3-6222593)
    
    [✓] VS Code (version 1.46.0)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.11.0
    
    [✓] Connected device (4 available)
        • SM M305F   • 32003c30dc19668f • android-arm64  • Android 10 (API 29)
        • macOS      • macOS            • darwin-x64     • Mac OS X 10.15.5 19F101
        • Web Server • web-server       • web-javascript • Flutter Tools
        • Chrome     • chrome           • web-javascript • Google Chrome
          83.0.4103.97
    
    • No issues found!
    
    
  11. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jun 16, 2020
  12. 10 remaining items

  13. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    on Jul 8, 2020
  14. removed this from the milestone on Jul 22, 2020
  15. markusaksli-nc commented on Aug 5, 2020

    @markusaksli-nc
    Contributor

    Hi @Piinks
    Since the original issue is no longer reproducible on the latest master and the skip audit has been merged can this be closed?
    Thank you

  16. Piinks commented on Aug 6, 2020

    @Piinks
    Contributor

    It looks like there are still 8 tests being skipped because of this issue, if they can be un-skipped and pass then this is resolved. It does not appear that it is though since they are still being skipped:

    https://github.com/flutter/flutter/blob/master/packages/flutter/test/services/raw_keyboard_test.dart

    https://github.com/flutter/flutter/blob/master/packages/flutter/test/widgets/focus_traversal_test.dart

    The skipped tests have a comment referencing this issue number so you can search for them. :)

  17. removed this from the milestone on Aug 17, 2020
  18. added
    team: skip-testAn issue used to track tests that are skipped.
    c: contributor-productivityTeam-specific productivity, code health, technical debt.
    c: tech-debtTechnical debt, code quality, testing, etc.
    on Aug 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: text inputEntering text in a text field or keyboard related problemsc: contributor-productivityTeam-specific productivity, code health, technical debt.c: tech-debtTechnical debt, code quality, testing, etc.frameworkflutter/packages/flutter repository. See also f: labels.platform-webWeb applications specificallyteam-webOwned by Web platform teamteam: skip-testAn issue used to track tests that are skipped.triaged-webTriaged by Web platform team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions