kasper / phoenix

A lightweight macOS window and app manager scriptable with JavaScript
https://kasper.github.io/phoenix/
Other
4.39k stars 128 forks source link

“Modifier released” event, or similar? #262

Open qqilihq opened 4 years ago

qqilihq commented 4 years ago

I’m using Phoenix with Cliclick (thanks for the hint somewhere here in the tickets!)

The challenge: When the handler is executed, the modifier keys might still be pressed (only the actual key has been released), thus the text to be inserted is typed while the modifiers are still down, which leads to unexpected behavior. I can work around this using a few ms wait.

Simple example:

Key.on('e', ['ctrl', 'shift'], () => {
  Task.run('/usr/local/bin/cliclick', ['w:100', 't:hello']);
});

Is there a possibility to (a) either execute the handler once all keys have been released, or (b) have some event which triggered once the modifiers are released, or (c) some other way which I haven’t thought of?

kasper commented 4 years ago

Hey @qqilihq! Interesting question. I think for a) the answer is no, since this is handled by the macOS API and the event is triggered natively. For b), this might be possible, but currently no such event is exposed through the Phoenix API. This might be something we can improve. I think the manual delay is likely the best stopgap for now.

rcarmo commented 3 years ago

Hi there,

I found this issue while looking for a way to capture mouse dragging (or rather, its end), and would also like to have this. I'm currently looking for a way to do window "drag and snap" to arbitrary zones, and without mouse event capture or just a simple modifier release, it's really hard to to.

kasper commented 3 years ago

@rcarmo Hi! Have you noticed the mouse events? https://github.com/kasper/phoenix/blob/2.6.7/docs/API.md#mouse. These events also provide the key modifiers that were active when the event happened. Combine with debouncing (https://lodash.com/docs/4.17.15#debounce) and you should be able achieve what you are looking for. Would that help?

rcarmo commented 3 years ago

Thanks, that sounds like a plan. Since there are so few examples, I overlooked them.

kasper commented 3 years ago

@rcarmo Let me know if there’s anything else you need help with. True, it might be valuable to add some more examples to the API documentation. Fair feedback! 🙂

rcarmo commented 3 years ago

Well, I've already got an XMonad-like tiling arrangement going: https://gist.github.com/rcarmo/1daccbe9abbbb5c133b7b48d05cc09e7 (am hacking another example, so this is missing some bits, but gives the general idea)