问题
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