RawKeyEvent wrong characters in Windows10 [Flutter desktop]

廉价感情. 提交于 2020-04-18 06:09:20

问题


I'm testing RawKeyboardListener in a Flutter Desktop project (Windows 10).

Events work fine, but i receive wrong keys label, as you can see below:

Is it a "keyboard layout" issue, like if the app was expecting events from an android keyboard with different key positions (As you can see in the .gif i receive and "Unknown Android key code")? How can i fix that?

Also, if i print event.isControlPressed it always return false even if i'm pressing it.

This is the code i'm using:

import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() {
  // See https://github.com/flutter/flutter/wiki/Desktop-shells#target-platform-override
  if (!kIsWeb && (Platform.isLinux || Platform.isWindows)) {
    debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia;
  }
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: RawKeyboardListener(
          child: TextField(),
          focusNode: FocusNode(),
          onKey: (event) async {
            if (event.runtimeType == RawKeyDownEvent) {
              print(
                  'id: ${event.logicalKey.keyId}, label: ${event.logicalKey.keyLabel} debugName: ${event.logicalKey.debugName}');
            }
          },
        ),
      ),
    );
  }
}

回答1:


That's a bug. There's nothing you can do at the level of your application to fix it.

Until it's fixed, the only thing you could do would be to write your key handling entirely in terms of key codes, rather than logical keys.



来源:https://stackoverflow.com/questions/60682045/rawkeyevent-wrong-characters-in-windows10-flutter-desktop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!