Closed leontea closed 5 years ago
There’s an explicit code path for Cmd+W and Cmd+Q handling in MASShortcutView
:
// If the shortcut is Cmd-W or Cmd-Q, cancel recording and pass the event through
else if ((shortcut.modifierFlags == NSCommandKeyMask) && (shortcut.keyCode == kVK_ANSI_W || shortcut.keyCode == kVK_ANSI_Q)) {
weakSelf.recording = NO;
}
When I comment that out and set a nil
validator for _customShortcutView
in the demo app, I can record and process Cmd+Q just fine. So it’s possible.
In theory, it would be nice for MASShortcutView
to not dictate any shortcut filter at all, just offer a reasonable default behaviour that could be turned off. I have done just that in #127 with shortcut validation. It would make sense to do the same with Cmd+Q and Cmd-W handling. Perhaps a boolean toggle? I don’t have the time at the moment, would you take a stab at it, @leontea?
Thanks Tomaz, hi Leon. I agree that such functionality is quite advanced for a standard setup. @leontea Please consider to make a fork and suggest a Pull Request if you believe the component wins from that. Kind regards!
Thanks, Zoul.
I actually did find that disabling the validator could be doing the job.
But soon, I encounter another problem. I've set cmd+L as a LockScreen key in the Keyboard Preference, and the demo failed to capture it since my mac just got locked after pressing the key. It is completely customized and it could be anything else. I can't just put all the possibilities in the IF statement.
What I mean here is that I want to capture any shortcut key without triggering the action no matter whether it is already assigned something by the user.
What I mean here is that I want to capture any shortcut key without triggering the action no matter whether it is already assigned something by the user.
Leon, MASShortcut
uses APIs which may sit on a higher level than some system shortcuts need. I believe hotkeys like Command-Tab must be treated differently and what you need here is a custom solution, additional to our component. Makes sense?
Thank you shpakovski. I have another question. How can I capture a single function key. For example, when I press the option key globally, I want my app to do something. I tried the following code, did not work. Could you give me some instructions?
MASShortcut *defaultShortcut = [MASShortcut shortcutWithKeyCode:58 modifierFlags:NSAlternateKeyMask];
[MASShortcut addGlobalHotkeyMonitorWithShortcut:defaultShortcut handler:^{
NSLog(@"pressed option key!");
}];
I think this is out of scope for MAS Shortcut, since the Option key itself is not a complete key shortcut. Take a look at event taps, they should be able to do what you want (monitor arbitrary keyboard events).
thanks a lot
You’re welcome! I will close this, but if you feel there is something more we could do for you, reopen or post a new issue.
For example, I want to capture the cmd+Q, but the demo app just quit because cmd+Q is the shortcut key for quitting application.