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

Cancel key combo when switching to a different window #16

Closed
DarkLight1337 opened this issue Jul 27, 2023 · 3 comments
Closed

Cancel key combo when switching to a different window #16

DarkLight1337 opened this issue Jul 27, 2023 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@DarkLight1337
Copy link

When I switch to a different window via keyboard (e.g. Alt+Tab), then return to the original window without using the keyboard (e.g. via clicking on it), the active key combo becomes stuck at the state before I left the window (e.g. at Alt), until I press and release the key again. This behaviour may confuse users into thinking that the key combos have stopped working.

It would be great if the active key combo automatically cancels when the window loses focus.

Here is a temporary solution that seems to work on keyboard shortcuts for tabbing out of the active window (I only tested on Windows though):

const keystrokes = new Keystrokes({
    selfReleasingKeys: [
        'ctrl', 'meta', 'alt', 'tab',
    ],
    keyRemap: {
        control: 'ctrl',
        os: 'meta',     // For Firefox
    },
});

addEventListener('blur', () => {
    // Prevent getting stuck in a key sequence after tabbing to a different window
    // @ts-expect-error
    keystrokes._tryReleaseSelfReleasingKeys();
});
@RobertWHurst
Copy link
Owner

RobertWHurst commented Jul 28, 2023

Yes, I had added this back with KeyboardJS. I'm trying to decide if this should go in the browser bindings, or in the library; I'm trying to decide if this is a platform dependent behavior or a general one. I'll try to get a solution together in the next day or so. Thanks for raising the issue @DarkLight1337

@RobertWHurst
Copy link
Owner

RobertWHurst commented Jul 28, 2023

Just put out a new release with this behavior added. Let me know if you have any issues.

@DarkLight1337
Copy link
Author

I've played around a bit and it seems to work as intended. Thanks!

@RobertWHurst RobertWHurst added the enhancement New feature or request label Aug 7, 2023
@RobertWHurst RobertWHurst self-assigned this Aug 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants