leanflutter / hotkey_manager

This plugin allows Flutter desktop apps to defines system/inapp wide hotkey (i.e. shortcut).
MIT License
134 stars 36 forks source link

Has a bug User macOS #19

Open lnd1992 opened 2 years ago

lnd1992 commented 2 years ago
import 'package:flutter/material.dart';
import 'package:hotkey_manager/hotkey_manager.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await hotKeyManager.unregisterAll();

  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  void initState() {
    super.initState();

    registerHotkey();
  }

  void registerHotkey() async {
    HotKey hotKey = HotKey(
      KeyCode.keyG,
      modifiers: [
        KeyModifier.meta,
      ],
      scope: HotKeyScope.inapp,
    );
    await hotKeyManager.register(
      hotKey,
      keyDownHandler: (hotKey) {
        print('onKeyDown+${hotKey.toJson()}');
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        color: const Color(0xFFDBDDE0).withOpacity(0.21),
        alignment: Alignment.center,
        child: const TextField(
          decoration: InputDecoration(hintText: 'search'),
        ),
      ),
    );
  }
}
lnd1992 commented 2 years ago

When the registration shortcut key, click common + G, you can print the log, and then click the input box to make it enter the editable state, click common can print the log

当注册快捷键之后,点击common+G,可以打印日志,再点击输入框使其进入可编辑状态,点击common就可以打印日志了

lnd1992 commented 2 years ago

我临时加了在下边两处加了 if (value.character == null) return;来解决这个问题

截屏2022-09-29 10 23 55 截屏2022-09-29 10 24 31

romannep commented 2 years ago

Looks like I have the same issue: hotkey with meta key fires on just meta key (command key in macOS) Tested on combination: Enter+Meta

ChenHaoTech commented 1 year ago

+1

ultrawideturbolife commented 1 year ago

me too, triggers on regular cmd. workaround is unregister and register with each keypress