MASShortcut
MASShortcut copied to clipboard
Execute action on key down too?
Is there a way to make the make the action execute on both key down and key up?
Sorry, not at the moment. (See MASShortcutMonitor
, we look for the kEventHotKeyPressed
event.) It should be trivial to patch the code yourself to watch both kEventHotKeyPressed
and kEventHotKeyReleased
, but I think the feature would be used so seldom it’s hard to justify adding it to MASShortcut. What’s your exact use case?
Thanks for the info @zoul! I'm writing an application that is momentarily activated while a hotkey is held, so active when pressed, inactive when released.
Ah, that makes good sense. In that case I suggest writing your own MASShortcutMonitor
class (it should be fairly simple to adapt it from the vanilla one) and plugging it into a MASShortcutBinder
, maybe even the shared one. Then you should get what you want while still keeping the rest of MASShortcut. Do you think that would work for you?
Thanks a lot for your suggestion @zoul! I'm pretty new to macOS/Cocoa development though and I'm not entirely sure if I understand you correctly. Should I write a new MASShortcutMonitor (not subclassing the existing one) and plug it into MASShortcutBinder using its setShortcutMonitor method?
In that case I’d think it would be easier for me to fork the repo and modify the existing MASShortcutMonitor to allow for the functionality. Or am I wrong thinking that or wrong in my understanding of your suggestion altogether?
You got my suggestion just right! The advantage in comparison to forking the repo is that you could keep using vanilla MASShortcut (except the monitor), getting new bug fixes, features etc. (But that’s just the first thing that came to my mind when thinking about your problem, so there might be an obvious downside somewhere.) I think we could even make MASShortcutMonitor
easier to modify, but I don’t have the time right now.
Cool! I'll give it a shot once I have time one of the coming days.
@zoul I gave that shot in: https://github.com/shpakovski/MASShortcut/pull/111