hotkey_manager
0.4.0, released 9 days ago by leanflutter.dev
Register system-wide and in-app keyboard shortcuts on desktop and Android
Uses material_ui
What it does
hotkey_manager lets you register global shortcuts that work even when your app is not focused, and in-app shortcuts that work with Flutter’s HardwareKeyboard. It uses nativeapi via Dart FFI for efficient, asynchronous registration across Windows, macOS, Linux and Android.
AI-written summary of version 0.4.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need a shortcut that works when the app is backgrounded
- You want to handle media keys or custom key combinations on desktop
- You need cross-platform support without writing platform-specific code
Skip it when
- You only need simple in-app shortcuts that can be handled by Flutter’s Shortcuts/Actions
- Your project targets older Flutter/Dart versions (pre 3.50/Dart 3.14)
Strengths
- Nativeapi integration gives fast, reliable global shortcuts
- Supports both global and in-app scopes with async registration
- Handles media keys and modifier-only shortcuts on all supported platforms
Weaknesses
- Requires Flutter 3.50+ and Dart 3.14, plus nativeapi 0.6.0
- Adds a native dependency that may increase build size
- Global shortcuts may conflict with system or other apps
Setup
- Kind
- Plugin (native code)
- Effort
- Medium
- Code generation
- No
- Direct dependencies
- 5
Add hotkey_manager and nativeapi 0.6.0+ to pubspec. No build_runner needed. No special permissions required beyond what nativeapi needs.
import 'package:hotkey_manager/native.dart' as hotkey;
final manager = hotkey.ShortcutManager.instance;
final listenerId = manager.addListener((event) {
if (event is hotkey.ShortcutActivatedEvent) {
print('Pressed: ${event.accelerator}');
}
});
final shortcut = manager.registerWithOptions(const hotkey.ShortcutOptions(
accelerator: 'Ctrl+Alt+Q',
description: 'Quick action',
scope: hotkey.ShortcutScope.global,
enabled: true,
));
if (shortcut == null) {
throw StateError('Shortcut unavailable or unsupported');
}
// ... later
manager.unregisterWithId(shortcut.id);
shortcut.dispose();
manager.removeListener(listenerId);Works with
Packages commonly used together with hotkey_manager: ones it builds on, ones built on it, and its own family.
- uuidhotkey_manager depends on itGenerates and parses RFC‑4122/9562 UUIDs (v1‑v8) for Dart.
- material_uihotkey_manager depends on itOfficial Flutter Material UI library implementing Google’s Material Design system.
- nativeapihotkey_manager depends on itDart bindings to native system APIs across desktop and mobile
- screen_retrieverSame familyRead desktop screen size, work area, scale factor and cursor position on Windows, macOS and Linux.
- window_managerSame familyFlutter desktop window resizing, moving, showing, hiding via nativeapi.
- tray_managerSame familyDefine system tray icons and context menus in Flutter desktop apps.
- nativeapi_flutterSame familyFlutter integration for nativeapi, adding widgets and type conversions.
- protocol_handlerSame familyRegister and handle custom protocols and deep links in Flutter apps.