hotkey_manager
This plugin allows Flutter desktop apps to defines system/inapp wide hotkey (i.e. shortcut).
This plugin allows Flutter desktop apps to defines system/inapp wide hotkey (i.e. shortcut).
^6.2.0English project snapshot. Visit GitHub for the latest content.
🚀 Ship Your App Faster: Try Fastforge - The simplest way to build, package and distribute your Flutter apps.
pub version https://img.shields.io/discord/884679008049037342.svg https://img.shields.io/badge/dynamic/json?label=Visits%20Count&query=value&url=https://api.countapi.xyz/hit/leanflutter.hotkey_manager/visits
This plugin allows Flutter desktop apps to defines system/inapp wide hotkey (i.e. shortcut).
English | 简体中文
| Linux | macOS | Windows |
|---|---|---|
| ✔️ | ✔️ | ✔️ |
Add this to your package's pubspec.yaml file:
dependencies:
hotkey_manager: ^0.2.3
Or
dependencies:
hotkey_manager:
git:
path: packages/hotkey_manager
url: https://github.com/leanflutter/hotkey_manager.git
ref: main
Run the following command
sudo apt-get install keybinder-3.0
import 'package:hotkey_manager/hotkey_manager.dart';
void main() 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.
// ⌥ + Q
HotKey _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.
HotKeyRecorder(
onHotKeyRecorded: (hotKey) {
_hotKey = hotKey;
setState(() {});
},
),
Please see the example app of this plugin for a full example.
| Method | Description | Linux | macOS | Windows |
|---|---|---|---|---|
| register | register an system/inapp wide hotkey. | ✔️ | ✔️ | ✔️ |
| unregister | unregister an system/inapp wide hotkey. | ✔️ | ✔️ | ✔️ |
| unregisterAll | unregister all system/inapp wide hotkeys. | ✔️ | ✔️ | ✔️ |