hotkey_manager
hotkey_manager copied to clipboard
Has a bug User macOS
import 'package:flutter/material.dart';
import 'package:hotkey_manager/hotkey_manager.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await hotKeyManager.unregisterAll();
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
void initState() {
super.initState();
registerHotkey();
}
void registerHotkey() async {
HotKey hotKey = HotKey(
KeyCode.keyG,
modifiers: [
KeyModifier.meta,
],
scope: HotKeyScope.inapp,
);
await hotKeyManager.register(
hotKey,
keyDownHandler: (hotKey) {
print('onKeyDown+${hotKey.toJson()}');
},
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
color: const Color(0xFFDBDDE0).withOpacity(0.21),
alignment: Alignment.center,
child: const TextField(
decoration: InputDecoration(hintText: 'search'),
),
),
);
}
}
When the registration shortcut key, click common + G, you can print the log, and then click the input box to make it enter the editable state, click common can print the log
当注册快捷键之后,点击common+G,可以打印日志,再点击输入框使其进入可编辑状态,点击common就可以打印日志了
我临时加了在下边两处加了 if (value.character == null) return;来解决这个问题
Looks like I have the same issue: hotkey with meta key fires on just meta key (command key in macOS) Tested on combination: Enter+Meta
- first time fires only on full combination
- after it every Meta press (Command) fires event. Reproduces only Meta key. Does not reproduces on Enter+Alt (option) for example
+1
me too, triggers on regular cmd. workaround is unregister and register with each keypress