jaywcjlove / hotkeys-js

➷ A robust Javascript library for capturing keyboard input. It has no dependencies.
https://jaywcjlove.github.io/hotkeys-js
MIT License
6.66k stars 410 forks source link

the callback is not executed when scope is' all ' #434

Open genguxuanyin opened 1 year ago

genguxuanyin commented 1 year ago

image Code update here, the key bind callback is not executed when scope is 'all'

genguxuanyin commented 1 year ago

The latest version will appear, version 3.10.2 is normal

jaywcjlove commented 1 year ago

@genguxuanyin Please provide a reproducible example.

jaywcjlove commented 1 year ago

@genguxuanyin https://codepen.io/jaywcjlove/full/XWyaKKa

genguxuanyin commented 1 year ago

@jaywcjlove https://codepen.io/genguxuanyin/pen/xxQXRXZ

When scope is "a", callbacks whose default scope is "all" should also be executed. The version 3.10.4 will appear, version 3.10.2 is normal.

image

jaywcjlove commented 1 year ago

@genguxuanyin You set scope to a but you didn't define a keyboard shortcut for a.

https://codepen.io/jaywcjlove/pen/KKrXNRY?editors=1010

- hotkeys('delete, command+backspace, backspace', (keyboardEvent, hotkeysEvent) => {
+ hotkeys('delete, command+backspace, backspace', 'a', (keyboardEvent, hotkeysEvent) => {
genguxuanyin commented 1 year ago

@genguxuanyin You set scope to a but you didn't define a keyboard shortcut for a.

https://codepen.io/jaywcjlove/pen/KKrXNRY?editors=1010

- hotkeys('delete, command+backspace, backspace', (keyboardEvent, hotkeysEvent) => {
+ hotkeys('delete, command+backspace, backspace', 'a', (keyboardEvent, hotkeysEvent) => {

I want this shortcut to run on all scopes, but it can't run when I set scope to "a",Or this will not be executed.

-hotkeys('delete, command+backspace, backspace', (keyboardEvent, hotkeysEvent) => {
+hotkeys('delete, command+backspace, backspace', 'all', (keyboardEvent, hotkeysEvent) => {

https://codepen.io/genguxuanyin/pen/xxQXRXZ When the version is 3.10.4, the callback is not executed when delete is pressed. When the version is 3.10.2, the callback is executed.

jaywcjlove commented 1 year ago

@genguxuanyin By default, scope is not given, and a value of all will be given globally. You changed the global value of scope to a, so it will not execute.

This behavior was fixed in #433, and if not fixed, would cause problems with executing callback methods multiple times.

genguxuanyin commented 1 year ago

In versions 3.10.2, callbacks executed by all scopes could be written using scope= 'all', now how should I write them?

jaywcjlove commented 1 year ago

@genguxuanyin You need all scope + custom scope to monitor, right?

qxang commented 1 year ago

@genguxuanyin hi, Have you solved this problem yet ?

qxang commented 1 year ago

@genguxuanyin I have the same ; How to solve it ?

jaywcjlove commented 1 year ago

@genguxuanyin @qxang upgrade v3.11.2