jaywcjlove / hotkeys-js

➷ A robust Javascript library for capturing keyboard input. It has no dependencies.

Home Page:https://jaywcjlove.github.io/hotkeys-js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

why 'trigger' callback has not arguments?

o-cc opened this issue · comments

commented

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.