Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

注册应用级别的热键,在macOS上按下的时候会咚的一声 #34

Closed
6ag opened this issue Sep 7, 2023 · 3 comments
Closed

Comments

@6ag
Copy link

6ag commented Sep 7, 2023

就像是快捷键冲突的那种提示音,注册系统级别的不会

@Eric0x
Copy link

Eric0x commented Nov 6, 2023

i had the same problem

@Zhoucheng133
Copy link

的确存在这样的问题,应该是没有聚焦,有一个比较折中的解决办法就是添加一个系统菜单:

if(Platform.isMacOS) PlatformMenuBar(
  menu: [
    // ...
  ]
)

详细写法:PlatformMenuBar class - Flutter API

然后添加一个shortcut属性就好了

@lijy91
Copy link
Member

lijy91 commented Mar 2, 2024

请升级到 v0.2.0,这个版本已经做了处理,具体看这里

bool _handleInAppHotKeyEvent(KeyEvent keyEvent) {
if (_hotKeyList.where((e) => e.scope == HotKeyScope.inapp).isEmpty) {
return false;
}
if (keyEvent is KeyUpEvent && _lastPressedHotKey != null) {
HotKeyHandler? handler = _keyUpHandlerMap[_lastPressedHotKey!.identifier];
if (handler != null) handler(_lastPressedHotKey!);
_lastPressedHotKey = null;
return true;
}
if (keyEvent is KeyRepeatEvent && _lastPressedHotKey != null) {
return true;
}
if (keyEvent is KeyDownEvent) {
final physicalKeysPressed = HardwareKeyboard.instance.physicalKeysPressed;
HotKey? hotKey = _hotKeyList.firstWhereOrNull(
(e) {
List<HotKeyModifier>? modifiers = HotKeyModifier.values
.where((e) => e.physicalKeys.any(physicalKeysPressed.contains))
.toList();
return e.scope == HotKeyScope.inapp &&
keyEvent.logicalKey == e.logicalKey &&
modifiers.every((e.modifiers ?? []).contains);
},
);
if (hotKey != null) {
HotKeyHandler? handler = _keyDownHandlerMap[hotKey.identifier];
if (handler != null) handler(hotKey);
_lastPressedHotKey = hotKey;
return true;
}
}
return false;
}

@lijy91 lijy91 closed this as completed Mar 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants