hotkey_manager 0.1.7 icon indicating copy to clipboard operation
hotkey_manager: ^0.1.7 copied to clipboard

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

hotkey_manager #

pub version

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


English | 简体中文


Platform Support #

LinuxmacOSWindows
✔️✔️✔️

Quick Start #

Installation #

Add this to your package's pubspec.yaml file:

dependencies:
  hotkey_manager: ^0.1.7

Or

dependencies:
  hotkey_manager:
    git:
      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(
  KeyCode.keyQ,
  modifiers: [KeyModifier.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? #

  • 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 #

MethodDescriptionLinuxmacOSWindows
registerregister an system/inapp wide hotkey.✔️✔️✔️
unregisterunregister an system/inapp wide hotkey.✔️✔️✔️
unregisterAllunregister all system/inapp wide hotkeys.✔️✔️✔️

License #

MIT

47
likes
130
pub points
91%
popularity

Publisher

verified publisher iconleanflutter.org

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

Repository (GitHub)

Documentation

API reference

License

Icon for licenses.MIT (LICENSE)

Dependencies

collection, flutter, flutter_web_plugins, uuid

More

Packages that depend on hotkey_manager