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

why 'trigger' callback has not arguments? #427

Open
o-cc opened this issue May 11, 2023 · 0 comments
Open

why 'trigger' callback has not arguments? #427

o-cc opened this issue May 11, 2023 · 0 comments

Comments

@o-cc
Copy link

o-cc commented May 11, 2023

useHotkeys is a hooks, to activate hotkeys-js.

// parent-component.
// ...
useHotkeys({ scope: "parent", keys: "p"}, (e) => {
 switch (e.shortcut) {
        case "r":
          hotkeys.trigger(e.shortcut, "child");
      }
});
// sub-component.
//  there are more than two keys in the sub-component.
useHotkeys({ scope: "child", keys: "s,c", autoMerge: true }, (e) => {
// after keys is enter & hotkeys.trigger
//e is undefined
});

finally, the p,s,c keys is activated;

why data.method has not arguments?

How can I know the current key, after hotkeys.trigger. I don't want to single maintain triggered keys.

// hotkeys-js

  function trigger(shortcut) {
    var scope = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'all';
    Object.keys(_handlers).forEach(function (key) {
      var dataList = _handlers[key].filter(function (item) {
        return item.scope === scope && item.shortcut === shortcut;
      });

      dataList.forEach(function (data) {
        if (data && data.method) {
          data.method(); // data.method(keyboardEvent, hotkeysEvent)?
        }
      });
    });
  }

maybe it can have parameters🤔🤔

Look forward to your kind advice.

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

1 participant