jaywcjlove / hotkeys-js

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

cannot detect shift keyup event #246

Open danhk0612 opened 3 years ago

danhk0612 commented 3 years ago

hotkeys("shift", { keyup: true }, function (evn, handler) { // eventFunction... }

if i press shift key, doesnt execute event function.

jaywcjlove commented 3 years ago

@danhk0612

hotkeys('*', function() {
  if (hotkeys.shift) {
    console.log('shift is pressed!');
  }
});
nc commented 3 years ago

+1 doesn't work for me either @danhk0612 did you find a workaround?

mattanimation commented 3 years ago

using the asterisk works, but if one just wants to get the shift event then it doesn't work. I'm using the react hooks version and even this:

useHotkeys('⇪,shiftKey,shift', (k)=>{
    console.log(k, hotkeys.getPressedKeyCodes());
  }, {keydown:true, keyup:true})

doesn't work. I've tried each on their own too, but only if I use the * does it work.

codingedgar commented 2 years ago

same thing, using the keyup doesn't work either

Hakityc commented 2 months ago

hotkeys监听不到shift up 我按了一下shift键,这是结果

oleksandr-danylchenko commented 2 months ago

@Tamcony, I don't think this is correct... Because on the keydown event the event.shiftKey can be true even if you press any shift+* combination. Moreover, on the keyup if the Shift key is lifted, the event.shiftKey won't be true. Instead, you should check for the hotkeys.shift && evt.key === 'Shift'