Search code examples
flutterkeyboard-shortcutsflutter-web

LogicalKeyboardKey.meta in shortcut is triggered without pressing the other keys in the LogicalKeySet


I've been working with Shortcuts, Actions and key binds with Flutter web. And I've found a weird behaviour that I can't find a solution to.

The thing is, I have defined a series of LogicalKeySet for a set of actions. I create 2 per action, one for windows and one for mac. They look something like this:

final boldKeySetWindows = LogicalKeySet(LogicalKeyboardKey.control, LogicalKeyboardKey.keyB);
final boldKeySetMac = LogicalKeySet(LogicalKeyboardKey.control, LogicalKeyboardKey.keyB);

I add them to the Actions widget as specified here.

final boldKeySetWindows = LogicalKeySet(LogicalKeyboardKey.control, LogicalKeyboardKey.keyB);
final boldKeySetMac = LogicalKeySet(LogicalKeyboardKey.control, LogicalKeyboardKey.keyB);

Shortcuts(
  shortcuts: {
    boldKeySetWindows: MEFormatIntent(boldFormatter),
    boldKeySetMac: MEFormatIntent(boldFormatter),
  },
  child: Actions(
    dispatcher: MEFormatActionDispatcher(),
    actions: <Type, Action<Intent>>{
      MEFormatIntent: MEFormatAction(_controller),
    },
  )
);

The problem or weird behaviour is the following, for windows (using control) it works fine, it only executes MEFormatAction when both ctrl and b are pressed.

But if I try using the meta key or key plus b it works correctly the first time you press cmd+b, but after that, if I quickly press cmd again, it executes MEFormatAction again. (This behaviour does not happen with ctrl)

Am I missing something, or is this a bug?

I have not tried anything as I have been unsuccessful in finding information regarding this behaviour, any help or advice is highly appreciated!


Solution

  • It's a known issue/behaviour, it seems an issue with MacOS, more information can be found here and here

    But the solution is to use, SingleActivator instead of LogicalKeySet