MASShortcut icon indicating copy to clipboard operation
MASShortcut copied to clipboard

Execute action on key down too?

Open yn5 opened this issue 7 years ago • 7 comments

Is there a way to make the make the action execute on both key down and key up?

yn5 avatar Mar 04 '17 18:03 yn5

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?

zoul avatar Mar 04 '17 18:03 zoul

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.

yn5 avatar Mar 07 '17 22:03 yn5

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?

zoul avatar Mar 08 '17 08:03 zoul

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?

yn5 avatar Mar 12 '17 18:03 yn5

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.

zoul avatar Mar 12 '17 18:03 zoul

Cool! I'll give it a shot once I have time one of the coming days.

yn5 avatar Mar 13 '17 03:03 yn5

@zoul I gave that shot in: https://github.com/shpakovski/MASShortcut/pull/111

yn5 avatar May 30 '17 16:05 yn5