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

binding detection does not work #426

Open
artola opened this issue May 6, 2023 · 8 comments
Open

binding detection does not work #426

artola opened this issue May 6, 2023 · 8 comments

Comments

@artola
Copy link

artola commented May 6, 2023

Multiple keystrokes without release are not properly detected and therefore the shortcut is not fired.

See for example the following Codepen. Here I just try to trap and handle "Cmd+R", when it is not properly detected it is caught Chrome and produces a page reload.

The sequence is:

  • press "Cmd" and do not release
  • press "0" (zero, like reset zoom)
  • press "R" (like reload page)

Use this debug page: https://cdpn.io/pen/debug/gOBvOXr?authentication_hash=ZoABapBwEZGr

The source of this repro: https://codepen.io/artola-the-decoder/pen/gOBvOXr

The expected behaviour is that after a non control key (I mean when a letter, number or symbol) is pressed, the logic should restart.

This sequence executed above: CMD + 0 + R, should be treated as CMD + 0 and CMD + R.

Here the same example refactored with mousetrap and it works as expected: https://codepen.io/artola-the-decoder/pen/zYmRxVB

@magicdawn
Copy link

I have a similar issue:

  • setup, command+left: action1, command+right: action2
  • press command and hold.
  • press left, and release, action1 triggered.
  • press right, system ring a bell warning. action 2 not triggered.

this breaks in v3.10.3, works as expected in v3.10.2

@jaywcjlove
Copy link
Owner

@magicdawn You can reproduce your error. https://codepen.io/jaywcjlove/pen/xxQdNQp?editors=0010

const scope = getScope();

if (_handlers[key][i].key && _handlers[key][i].scope === scope) {

@magicdawn
Copy link

@jaywcjlove

Key sequence

  1. press command and hold.
  2. press left and release, expect you pressed command + left
  3. press right and release, expect you pressed command + right

v3.10.2 works as expected, v3.10.3 step 3 not showing

@jaywcjlove
Copy link
Owner

@magicdawn Upgrade v3.10.4

@artola
Copy link
Author

artola commented Jul 2, 2023

@jaywcjlove It seems that the fix does not work for the above mentioned example, upgraded to v3.10.4:

https://codepen.io/artola-the-decoder/pen/gOBvOXr

@jaywcjlove
Copy link
Owner

@artola https://codepen.io/jaywcjlove/pen/NWEgNqo?editors=1010

import hotkeysJs from "https://cdn.skypack.dev/[email protected]";

window.addEventListener("DOMContentLoaded", (event) => {
  const button = document.querySelector('button');

  button.focus();

  hotkeys('command+r,command+r+0', undefined, (keyboardEvent, hotkeysEvent) => {
    keyboardEvent.preventDefault();
    keyboardEvent.stopPropagation();

    button.innerHTML = "prevented";

    return false;
  });
});

@artola
Copy link
Author

artola commented Jul 3, 2023

This sequence executed above: CMD + 0 + R, should be treated as CMD + 0 and CMD + R.

Thanks @jaywcjlove. But look in my original issue, my expectation is:

This sequence executed above: CMD + 0 + R, should be treated as CMD + 0 and CMD + R.

If that is fulfilled, then the code should trap the keystrokes and avoid a page reload without changing the listeners, but it does not:

import hotkeysJs from "https://cdn.skypack.dev/[email protected]";

window.addEventListener("DOMContentLoaded", (event) => {
  const button = document.querySelector('button');

  button.focus();

  hotkeys('command+r', undefined, (keyboardEvent, hotkeysEvent) => {
    keyboardEvent.preventDefault();
    keyboardEvent.stopPropagation();

    button.innerHTML = "prevented";

    return false;
  });
});

@jinxxxxxi
Copy link

@jaywcjlove

Key sequence

  1. press command and hold.
  2. press left and release, expect you pressed command + left
  3. press right and release, expect you pressed command + right

v3.10.2 works as expected, v3.10.3 step 3 not showing

I have a similar problem:
setup:[cmd+shift+k] and [cmd+shift+b] shortcuts

  1. press [cmd+shift] , and hold them
  2. press k, it worked.
  3. release k and press b, it doesn't work.

I think may be you have fixed problem about [cmd+] but not [cmd+shift+].

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

4 participants