Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: let callback signal to KeyAction::Allow the keypress #4

Open
shaver opened this issue Feb 19, 2025 · 4 comments
Open

feat: let callback signal to KeyAction::Allow the keypress #4

shaver opened this issue Feb 19, 2025 · 4 comments

Comments

@shaver
Copy link

shaver commented Feb 19, 2025

I want to contextually determine in my app logic whether a hotkey applies, such as

  • based on what window has focus
  • based on what virtual desktop is selected
  • supporting a global "paused" state that ignores all registered hotkeys except the one to unpause (ideally logging that the key was ignored, for diagnostic purposes)

Currently, these require unregistering and reregistering hotkeys at each state change, which is a bit clumsy, and the logic to allow normal key action processing seems like it would be straightforward given a way for the callback to communicate that desire.

What do you think of a way for the callback to signal that the key action should be allowed instead of blocked?

Thanks for a delightfully clean and simple crate!

@iholston
Copy link
Owner

This is definitely needed, I plan on having a pause feature implemented in the next release 👍

@shaver
Copy link
Author

shaver commented Feb 20, 2025

Pause sounds good, but without the ability to keep a keybinding active I won't be able to let users unpause. For that I think I need the client code to be able to signal whether the key should get its normal processing or not.

Do you have plans for that as well? I can think of a couple of ways to do it, such as a magic return type that win-hotkeys specializes on for the callback, or a mutable parameter to the callback.

If not then I'll proceed with reorganizing my client to unregister/re-register on focus change or similar. Which is fine, certainly, but this seemed like a useful facility for clients to have, so I thought I'd ask!

@iholston
Copy link
Owner

My current plan is to implement a pause handle. You can add the pause handle to the callback of a hotkey or use it independently. Calling toggle_pause on the handle will pause processing of any hotkeys other than the specified pause/unpause hotkey(s). Which would have the effect that I think you are looking for

@shaver
Copy link
Author

shaver commented Feb 21, 2025

Oh excellent! I'll watch for that change, and please let me know if you want me to test anything in progress. Thanks again for this great work.

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

No branches or pull requests

2 participants