import'package:hotkey_manager/hotkey_manager.dart';
voidmain() async {
// Must add this line.WidgetsFlutterBinding.ensureInitialized();
// For hot reload, `unregisterAll()` needs to be called.await hotKeyManager.unregisterAll();
runApp(MyApp());
}
Register/Unregsiter a system/inapp wide hotkey.
// ⌥ + QHotKey _hotKey = HotKey(
key: PhysicalKeyboardKey.keyQ,
modifiers: [HotKeyModifier.alt],
// Set hotkey scope (default is HotKeyScope.system)
scope: HotKeyScope.inapp, // Set as inapp-wide hotkey.
);
await hotKeyManager.register(
_hotKey,
keyDownHandler: (hotKey) {
print('onKeyDown+${hotKey.toJson()}');
},
// Only works on macOS.
keyUpHandler: (hotKey){
print('onKeyUp+${hotKey.toJson()}');
} ,
);
await hotKeyManager.unregister(_hotKey);
await hotKeyManager.unregisterAll();
Use HotKeyRecorder widget to help you record a hotkey.