# hotkey_manager **Repository Path**: leanflutter/hotkey_manager ## Basic Information - **Project Name**: hotkey_manager - **Description**: 这个插件允许 Flutter 桌面 应用定义系统/应用范围内的热键(即快捷键)。 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2021-08-01 - **Last Updated**: 2024-10-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: Flutter, Linux, macOS, Windows, hotkey ## README # hotkey_manager [![pub version][pub-image]][pub-url] [![][discord-image]][discord-url] ![][visits-count-image] [pub-image]: https://img.shields.io/pub/v/hotkey_manager.svg [pub-url]: https://pub.dev/packages/hotkey_manager [discord-image]: https://img.shields.io/discord/884679008049037342.svg [discord-url]: https://discord.gg/zPa6EZ2jqb [visits-count-image]: 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 | [简体中文](./README-ZH.md) --- - [hotkey_manager](#hotkey_manager) - [Platform Support](#platform-support) - [Quick Start](#quick-start) - [Installation](#installation) - [Linux requirements](#linux-requirements) - [Usage](#usage) - [Who's using it?](#whos-using-it) - [API](#api) - [HotKeyManager](#hotkeymanager) - [Related Links](#related-links) - [License](#license) ## Platform Support | Linux | macOS | Windows | | :---: | :---: | :-----: | | ✔️ | ✔️ | ✔️ | ## Quick Start ### Installation Add this to your package's pubspec.yaml file: ```yaml dependencies: hotkey_manager: ^0.2.3 ``` Or ```yaml dependencies: hotkey_manager: git: path: packages/hotkey_manager url: https://github.com/leanflutter/hotkey_manager.git ref: main ``` #### Linux requirements - [`keybinder-3.0`](https://github.com/kupferlauncher/keybinder) Run the following command ``` sudo apt-get install keybinder-3.0 ``` ### Usage ```dart 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. ```dart // ⌥ + 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. ```dart HotKeyRecorder( onHotKeyRecorded: (hotKey) { _hotKey = hotKey; setState(() {}); }, ), ``` > Please see the example app of this plugin for a full example. ## Who's using it? - [Airclap](https://airclap.app/) - Send any file to any device. cross platform, ultra fast and easy to use. - [AuthPass](https://authpass.app/) - Password Manager based on Flutter for all platforms. Keepass 2.x (kdbx 3.x) compatible. - [Biyi (比译)](https://biyidev.com/) - A convenient translation and dictionary app. ## API ### HotKeyManager | 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. | ✔️ | ✔️ | ✔️ | ## Related Links - https://github.com/soffes/HotKey - https://github.com/kupferlauncher/keybinder ## License [MIT](./LICENSE)