创建一个只听 macOS 上的命令键的键盘快捷键
Create a keyboard shortcut that only listens to the command key on macOS
如何只为 cmd 键创建键盘快捷键? UIKeyCommand
的初始化器还需要一个非空的常规键(input
)沿着修饰符标志(cmd 在我的例子中)所以它不起作用通过 nil
.
时
我知道有可能,因为 Paste 和 Slack 也在做同样的事情,但我没有使用 macOS 的经验来解决这个问题。
这 不是 Detect any key press, including modifier keys, on OS X 的副本,因为该问题措辞怪异,在 Google 上排名较低。我搜索了几天来寻找这个问题的答案,但找不到任何答案,所以我将其打开以便于查找。
您可以使用:
[NSEvent addLocalMonitorForEventsMatchingMask:NSEventMaskFlagsChanged handler:^NSEvent *(NSEvent *incomingEvent) {
if (incomingEvent.modifierFlags & NSEventModifierFlagCommand) {
NSLog(@"command key down");
}
return incomingEvent;
}];
如何只为 cmd 键创建键盘快捷键? UIKeyCommand
的初始化器还需要一个非空的常规键(input
)沿着修饰符标志(cmd 在我的例子中)所以它不起作用通过 nil
.
我知道有可能,因为 Paste 和 Slack 也在做同样的事情,但我没有使用 macOS 的经验来解决这个问题。
这 不是 Detect any key press, including modifier keys, on OS X 的副本,因为该问题措辞怪异,在 Google 上排名较低。我搜索了几天来寻找这个问题的答案,但找不到任何答案,所以我将其打开以便于查找。
您可以使用:
[NSEvent addLocalMonitorForEventsMatchingMask:NSEventMaskFlagsChanged handler:^NSEvent *(NSEvent *incomingEvent) {
if (incomingEvent.modifierFlags & NSEventModifierFlagCommand) {
NSLog(@"command key down");
}
return incomingEvent;
}];