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

seperate each hotkey event calls using same shortcut keys #341

Open ladypython247 opened 2 years ago

ladypython247 commented 2 years ago

I have two div A and div B I want to add same keyboard shortcuts, ctrl+up and ctrl+down works alright, but the problem begins when I navigate with the arrow (hotkeys shortcut) it logs both shortcut key ctrl+up in div a and div b. How do I avoid this.

hotkeys('left', 'forms', function(handler, event) {
 if(handler.shortcut=="ctrl+down"){
console.log("left", "down")
}if(handler.shortcut=="ctrl+up"){
console.log("left", "up")
}
});

hotkeys('right', 'files', function(handler, event) {
 if(event.shortcut=="ctrl+down"){
console.log("right", "down")
}if(event.shortcut=="ctrl+up"){
console.log("right", "up")
}
});

This is my example code. I have looked at the setScope still don't how to apply it to the code above.

Yukiniro commented 2 years ago

I can not reappear this problem. Could you offer a online example. For example this.