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

Hotkey held status not cleared if you open a new tab or focus is lost for example. #9

Open
LiamKarlMitchell opened this issue Jul 30, 2022 · 6 comments

Comments

@LiamKarlMitchell
Copy link
Contributor

LiamKarlMitchell commented Jul 30, 2022

window.open(card.url, '_blank', 'noopener')

Could possibly use visibility change event listener to clear any held keys when window/tab looses focus?

document.addEventListener("visibilitychange", onchange)

Or maybe it should clear when handler is executed?

Similar when using a Screen Shot tool like Lightshot, which steals the focus away, the key up event is not received.

@Talljack
Copy link
Owner

window.open(card.url, '_blank', 'noopener')

Could possibly use visibility change event listener to clear any held keys when window/tab looses focus?

document.addEventListener("visibilitychange", onchange)

Or maybe it should clear when handler is executed?

Similar when using a Screen Shot tool like Lightshot, which steals the focus away, the key up event is not received.

oh,I will check it, if there is such a problem, I will take your advice, thank you

@Talljack
Copy link
Owner

do you want to say document.hasFocus()?

@LiamKarlMitchell
Copy link
Contributor Author

Any time the focus is lost the keyup event isn't sent to the browser of course.

  1. So when the document gets focus again I think it needs to clear the keys that are pressed.
  2. And possibly when the handler is triggered for a known key sequence, it should clear pressed keys maybe.

@Talljack
Copy link
Owner

Talljack commented Aug 1, 2022

Any time the focus is lost the keyup event isn't sent to the browser of course.

  1. So when the document gets focus again I think it needs to clear the keys that are pressed.
  2. And possibly when the handler is triggered for a known key sequence, it should clear pressed keys maybe.

I think it's possible

@LiamKarlMitchell
Copy link
Contributor Author

LiamKarlMitchell commented Aug 1, 2022

Yeah I think the main issue with my thoughts above is preventing it firing constantly when you are holding the keys which is why keyup is used to clear their states?

Which could possibly be worked around with a busy flag can't recall if I saw one in the code.

if (hotkeyInUse) {
  return
}

// When hotkey handler is triggered
hotkeyInUse = true

// When focus is returned
hotkeyInUse = false

// When all the keys are up
hotkeyInUse = false

But this could prevent people doing combination hot keys in a sequence around the modifier keys.

Like Ctrl + A, Ctrl + B as two separate hotkeys but the user does not let go of Ctrl.

@Talljack
Copy link
Owner

Talljack commented Aug 1, 2022

Yeah, I didn't think of that,would you have time to pr? thank you

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