Skip to content
This repository has been archived by the owner on Mar 5, 2023. It is now read-only.

Execute action on key down too? #107

Open
yn5 opened this issue Mar 4, 2017 · 7 comments
Open

Execute action on key down too? #107

yn5 opened this issue Mar 4, 2017 · 7 comments

Comments

@yn5
Copy link

yn5 commented Mar 4, 2017

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

@zoul
Copy link
Collaborator

zoul commented Mar 4, 2017

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?

@yn5
Copy link
Author

yn5 commented Mar 7, 2017

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.

@zoul
Copy link
Collaborator

zoul commented Mar 8, 2017

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?

@yn5
Copy link
Author

yn5 commented Mar 12, 2017

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?

@zoul
Copy link
Collaborator

zoul commented Mar 12, 2017

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.

@yn5
Copy link
Author

yn5 commented Mar 13, 2017

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

@yn5
Copy link
Author

yn5 commented May 30, 2017

@zoul I gave that shot in: #111

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants