hotkey_system 0.0.4 copy "hotkey_system: ^0.0.4" to clipboard
hotkey_system: ^0.0.4 copied to clipboard

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

HotkeySystem

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


English | Turkish


Platform Support #

macOS
✔️

Quick Start #

Installation #

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

dependencies:
  hotkey_system: ^0.0.4

Or

dependencies:
  hotkey_system:
    git:
      url: https://github.com/suysoftware/hotkey_system.git
      ref: main

Linux requirements

Run the following command

sudo apt-get install keybinder-3.0

Usage #

import 'package:hotkey_system/hotkey_system.dart';

void main() async {
  // Must add this line.
  WidgetsFlutterBinding.ensureInitialized();
  // For hot reload, `unregisterAll()` needs to be called.
  await hotKeySystem.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 hotKeySystem.register(
  _hotKey,
  keyDownHandler: (hotKey) {
    print('onKeyDown+${hotKey.toJson()}');
  },
  // Only works on macOS.
  keyUpHandler: (hotKey){
    print('onKeyUp+${hotKey.toJson()}');
  } ,
);

await hotKeySystem.unregister(_hotKey);

await hotKeySystem.unregisterAll();

Use HotKeyRecorder widget to help you record a hotkey.

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

Use HotKeyRecorder widget with initialHotkey

HotKeyRecorder(
  onHotKeyRecorded: (hotKey) {
    _hotKey = hotKey;
    setState(() {});
  },
  initialHotKey: HotKey.fromJson({"keyCode":"keyR","modifiers":["meta"],"identifier":"fdf8484b-5249-42bb-b473-d99bfb7bb3e8","scope":"system"})
),

Register with identifier

// ⌥ + Q
HotKey _hotKey = HotKey(
  KeyCode.keyQ,
  modifiers: [KeyModifier.alt],
  identifier: "examleidentifier"
  // Set hotkey scope (default is HotKeyScope.system)
  scope: HotKeyScope.inapp, // Set as inapp-wide hotkey.
);
await hotKeySystem.register(
  _hotKey,
  keyDownHandler: (hotKey) {
    print('onKeyDown+${hotKey.toJson()}');
  },
  // Only works on macOS.
  keyUpHandler: (hotKey){
    print('onKeyUp+${hotKey.toJson()}');
  } ,
);

Hotkey.fromJson usage

HotKey _hotKey = HotKey.fromJson({"keyCode":"keyR","modifiers":["meta"],"identifier":"fdf8484b-5249-42bb-b473-d99bfb7bb3e8","scope":"system"})
await hotKeySystem.register(
  _hotKey,
  keyDownHandler: (hotKey) {
    print('onKeyDown+${hotKey.toJson()}');
  },
  // Only works on macOS.
  keyUpHandler: (hotKey){
    print('onKeyUp+${hotKey.toJson()}');
  } ,
);

HotKeyVirtualView usage

 
return HotKeyVirtualView(HotKey.fromJson({"keyCode":"keyR","modifiers":["meta"],"identifier":"fdf8484b-5249-42bb-b473-d99bfb7bb3e8","scope":"system"}));

Please see the example app of this plugin for a full example.

Who's using it? #

  • ThinkBuddy - Made for native MacOS experience integrated with AI

API #

HotKeySystem #

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. ✔️ ✔️ ✔️

License #

MIT

14
likes
0
points
34
downloads

Publisher

unverified uploader

Weekly Downloads

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

Repository (GitHub)
View/report issues

Topics

#hotkey #shortcuts #keyboard #macos-shortcuts #hardware-keyboard

License

unknown (license)

Dependencies

collection, flutter, uuid

More

Packages that depend on hotkey_system