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

Feature Request: non-global / focus-only shortcuts #2482

Closed
adam-lynch opened this issue Oct 20, 2014 · 5 comments
Closed

Feature Request: non-global / focus-only shortcuts #2482

adam-lynch opened this issue Oct 20, 2014 · 5 comments
Labels

Comments

@adam-lynch
Copy link

It would be great if when assigning shortcuts, that we could pass global: false or something so the active callback would only be called if the app is focused.

I guess we could check ourselves if the app is focused, but maybe it would more efficient not to catch the keys at all when the app is blurred on a lower level?

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@CaptainYarb
Copy link

@adam-lynch You can bind to events when the app is focused like you would in a normal HTML/JS application. Take a look at these:

Or if you use something like jQuery there are a few different ways to approach that.

@adam-lynch
Copy link
Author

@Blazedd I don't think that answers what I'm looking for 😄.

Plus the following is basically the same as checking in the callback like I said originally:

You can bind to events when the app is focused like you would in a normal HTML/JS application

I'm saying maybe it's better that node-webkit wouldn't catch the keys at all when the app isn't focused.

@CaptainYarb
Copy link

@adam-lynch The whole point of the shortcut events is allow the app to capture the events globally. Otherwise you can use the methods above to check that. Optionally you can check if the window is focused when you bind to your shortcut as well. Are you looking for an easy way to bind to specific key binding? The keydown doesn't give you a verbose "CTRL+A" setup, but there are libraries that do. I don't understand what you are needing that isn't already available.

@adam-lynch
Copy link
Author

@Blazedd I understand how to bind key events, etc. It's not that it's technically impossible as is, I'm simply asking for the option to not make the shortcuts global, as a built-in option in the shortcuts API. If you don't want it, that's ok.

It would be handy. Otherwise, let's say you don't know how many windows will be open at once. You then need to:

  • Keep track of all open windows; maintain an array and bind a close event handler for each window.
  • Bind focus & blur event handlers to each window and store a isFocused Boolean somewhere for each window.
  • When the key event callback is triggered by the Shortcuts API, loop over the open windows
  • If and only if all windows are blurred, then run the custom logic.

global: false would be a lot nicer.

@stale
Copy link

stale bot commented Sep 30, 2017

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Sep 30, 2017
@stale stale bot closed this as completed Oct 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants