hotkeys-js icon indicating copy to clipboard operation
hotkeys-js copied to clipboard

Can't detect shift alone

Open ashconnell opened this issue 4 years ago • 6 comments

Shift by itself doesn't work.

hotkeys('shift', function() {
  console.log('Shift pressed')
})

Here's a working example: CodeSandbox

ashconnell avatar Jul 02 '20 03:07 ashconnell

@ashconnell Modifier keys cannot be set.

hotkeys("*", function(event, handler) {
  console.log("event", event);
  console.log("handler", handler);
  if (hotkeys.shift) {
    console.log("shift is pressed!");
  }

  if (hotkeys.ctrl) {
    console.log("ctrl is pressed!");
  }

  if (hotkeys.alt) {
    console.log("alt is pressed!");
  }

  if (hotkeys.option) {
    console.log("option is pressed!");
  }

  if (hotkeys.control) {
    console.log("control is pressed!");
  }

  if (hotkeys.cmd) {
    console.log("cmd is pressed!");
  }

  if (hotkeys.command) {
    console.log("command is pressed!");
  }
});

jaywcjlove avatar Jul 02 '20 03:07 jaywcjlove

@jaywcjlove how would I differentiate between shift and shift+command+z then? I don't want the shift behaviour to happen when they actually pressed other keys with it

ashconnell avatar Jul 02 '20 04:07 ashconnell

@ashconnell Could you find anything?

m98 avatar Mar 08 '21 10:03 m98

@m98 I wrote my own key state machine where if "shift + command + z" is down then it "cancels" the "shift" binding

ashconnell avatar Mar 08 '21 11:03 ashconnell

@ashconnell You mean by using this library? or just writing it by your own code?

m98 avatar Mar 08 '21 11:03 m98

@jaywcjlove how would I differentiate between shift and shift+command+z then? I don't want the shift behaviour to happen when they actually pressed other keys with it

I guess if we make two binding, when we want them to trigger independently, or does binding z does not trigger if we bind shift+command+z?

codingedgar avatar Nov 22 '21 16:11 codingedgar