1 Star 1 Fork 0

LeanFlutter / hotkey_manager

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

hotkey_manager

pub version

这个插件允许 Flutter 桌面应用定义系统/应用范围内的热键(即快捷键)。


English | 简体中文


平台支持

Linux macOS Windows
✔️ ✔️ ✔️

快速开始

安装

将此添加到你的软件包的 pubspec.yaml 文件:

dependencies:
  hotkey_manager: ^0.2.2

dependencies:
  hotkey_manager:
    git:
      path: packages/hotkey_manager
      url: https://github.com/leanflutter/hotkey_manager.git
      ref: main

Linux requirements

运行以下命令

sudo apt-get install keybinder-3.0

用法

import 'package:hotkey_manager/hotkey_manager.dart';

void main() async {
  // 必须加上这一行。
  WidgetsFlutterBinding.ensureInitialized();
  // 对于热重载,`unregisterAll()` 需要被调用。
  await hotKeyManager.unregisterAll();

  runApp(MyApp());
}

注册/卸载一个系统/应用范围的热键。

// ⌥ + Q
HotKey _hotKey = HotKey(
  key: PhysicalKeyboardKey.keyQ,
  modifiers: [HotKeyModifier.alt],
  // 设置热键范围(默认为 HotKeyScope.system)
  scope: HotKeyScope.inapp, // 设置为应用范围的热键。
);
await hotKeyManager.register(
  _hotKey,
  keyDownHandler: (hotKey) {
    print('onKeyDown+${hotKey.toJson()}');
  },
  // 只在 macOS 上工作。
  keyUpHandler: (hotKey){
    print('onKeyUp+${hotKey.toJson()}');
  } ,
);

await hotKeyManager.unregister(_hotKey);

await hotKeyManager.unregisterAll();

使用 HotKeyRecorder 小部件帮助您录制一个热键。

HotKeyRecorder(
  onHotKeyRecorded: (hotKey) {
    _hotKey = hotKey;
    setState(() {});
  },
),

请看这个插件的示例应用,以了解完整的例子。

谁在用使用它?

  • Airclap - 任何文件,任意设备,随意发送。简单好用的跨平台高速文件传输APP。
  • AuthPass - 基于Flutter的密码管理器,适用于所有平台。兼容Keepass 2.x(kdbx 3.x)。
  • Biyi (比译) - 一个便捷的翻译和词典应用程序。

API

HotKeyManager

Method Description Linux macOS Windows
register 注册一个系统/应用范围的热键。 ✔️ ✔️ ✔️
unregister 取消注册一个系统/应用范围的热键。 ✔️ ✔️ ✔️
unregisterAll 取消注册全部系统/应用范围的热键。 ✔️ ✔️ ✔️

相关链接

许可证

MIT

MIT License Copyright (c) 2022-2024 LiJianying <lijy91@foxmail.com> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

这个插件允许 Flutter 桌面 应用定义系统/应用范围内的热键(即快捷键)。 展开 收起
Dart 等 6 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/leanflutter/hotkey_manager.git
git@gitee.com:leanflutter/hotkey_manager.git
leanflutter
hotkey_manager
hotkey_manager
main

搜索帮助

53164aa7 5694891 3bd8fe86 5694891