搜索插件、代码仓与 APP 分类

插件详情v0.3.0

hotkey_manager

此插件允许 Flutter 桌面应用程序定义系统/应用内全局快捷键(即快捷方式)。

macOSWindowsLinux
近 30 天下载
6.8万
喜欢数
147
Pub 分数
140

安装插件

flutter pub add hotkey_manager

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

hotkey_manager 包使 Flutter 桌面应用程序能够在 macOS、Windows 和 Linux 上注册并响应系统级或应用内键盘快捷键。它允许开发者定义自定义快捷键,无论当前活动的应用程序如何,都能触发特定操作,从而提升用户生产力和可访问性。该插件与 Flutter 的事件处理机制无缝集成,提供了一个简单的 API 来管理诸如 Ctrl+Shift+S 或 Cmd+T 等按键组合。非常适合需要快速访问功能而无需浏览菜单的应用。

适合场景

  • 为应用操作创建全局快捷方式
  • 快速访问常用功能
  • 通过键盘导航提升可访问性
  • 使用快捷键支持构建生产力工具
  • 与现有桌面工作流程集成

主要特点

  • 支持跨平台的系统级快捷键
  • 用于定义快捷键组合的简单 API
  • 跨平台兼容性(macOS、Windows、Linux)
  • 与 Flutter 应用的非侵入式集成
  • 处理冲突和重复注册

适合对象

  • 面向多个操作系统的桌面应用程序开发者
  • 生产力和实用软件
  • 需要高级键盘交互的应用程序
  • 开发可访问的桌面体验的开发者

使用建议

  • 在某些系统上需要平台特定的权限
  • 可能与现有系统快捷键冲突
  • 仅限桌面平台
  • 需要适当的清理以避免内存泄漏
  • 不适用于移动或Web应用程序

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

🚀 Ship Your App Faster: Try Fastforge - The simplest way to build, package and distribute your Flutter apps.

hotkey_manager

pub version

This plugin allows Flutter desktop apps to defines system/inapp wide hotkey (i.e. shortcut).


English | 简体中文


Platform Support

Linux macOS Windows
✔️ ✔️ ✔️

Quick Start

Installation

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
Linux requirements

Run the following command

sudo apt-get install keybinder-3.0
Usage
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.

Who's using it?

  • Airclap - Send any file to any device. cross platform, ultra fast and easy to use.
  • AuthPass - Password Manager based on Flutter for all platforms. Keepass 2.x (kdbx 3.x) compatible.
  • Biyi (比译) - 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

所属分类

依赖

依赖清单 4 项

  • hotkey_manager_platform_interface^0.2.0
  • nativeapi^0.5.6
  • uni_platform^0.1.3
  • uuid>=3.0.7 <5.0.0

源码仓库

使用此插件的项目