flutter_hotkeys

pub package License: MIT

The ultimate global and scoped keyboard shortcut manager for Flutter. Register shortcuts like ctrl+s or cmd+shift+p with a simple, high-performance static API.

Tip

AI Agent Friendly: This package is designed with structured APIs and O(1) matching, making it easy for AI agents to integrate and use in generated code.

Why flutter_hotkeys?

Search terms: flutter hotkeys, global shortcuts, keyboard events, desktop hotkeys, web shortcuts, react-hotkeys flutter, keyboard manager.

Works on Desktop (Windows, macOS, Linux), Web, and Mobile (External Keyboards).

Features

  • 🌍 Global Hotkeys: Register shortcuts that work anywhere in your app.
  • 🎯 Scoped Hotkeys: Register shortcuts that only trigger when a specific widget is focused.
  • ⌨️ Human-Readable Syntax: Use strings like ctrl+s or cmd+shift+p.
  • O(1) Performance: Ultra-fast shortcut matching using a central registry.
  • 🛠️ Modifier Support: full support for ctrl, alt, shift, meta/cmd.

Installation

Add flutter_hotkeys to your pubspec.yaml:

dependencies:
  flutter_hotkeys: ^1.0.0

Usage

Global Hotkeys

Register a shortcut anywhere in your app:

import 'package:flutter_hotkeys/flutter_hotkeys.dart';

// Register
Hotkeys.register('ctrl+s', () {
  print('Save triggered!');
});

// Unregister
Hotkeys.unregister('ctrl+s');

Scoped Hotkeys

Use HotkeyScope to define shortcuts that only work when a specific part of the UI is focused (e.g., an editor).

HotkeyScope(
  shortcuts: {
    'ctrl+b': () => makeBold(),
    'ctrl+i': () => makeItalic(),
  },
  child: TextField(
    decoration: InputDecoration(labelText: 'Focused Editor'),
  ),
)

Syntax Reference

Supported Modifiers:

  • ctrl / control
  • alt / option
  • shift
  • meta / cmd / command / win

Examples:

  • ctrl+s
  • ctrl+shift+p
  • alt+enter
  • cmd+k
  • f1
  • enter, escape, backspace, del

Comparison with Flutter Shortcuts API

Feature flutter_hotkeys Flutter Shortcuts / Actions
Simplicity Extremely Simple (Static API) Complex (Intent/Action/Shortcut boilerplate)
Global Scope Native Support Difficult to implement globally
Syntax String-based (ctrl+s) Class-based (SingleActivator)
Focus required Optional Required for standard shortcuts

License

This project is licensed under the MIT License - see the LICENSE file for details.

Libraries

flutter_hotkeys