liftoff / HumanInput

A JavaScript library for handling keyboard shortcuts and other human-generated events
Apache License 2.0
583 stars 25 forks source link

[BUG] MAC OS X `command + c` broke all #6

Open lokhmakov opened 8 years ago

lokhmakov commented 8 years ago
  1. After single press command + c HumanInput thinks that I hold c
  2. After 5000ms pseudo hold HumanInput react on watchers and thinks that already c holded
  3. After some timeout HumanInput starts work normaly, in DEBUG no info
  4. http://jsbin.com/bexojekapi/1/edit?html,js,output
  5. http://imgur.com/DZtvWpp
lokhmakov commented 8 years ago

After pressing only Enter and HI.pause() - HumanInput thinks that I hold Enter

liftoff commented 8 years ago

What browser/version are you using?

lokhmakov commented 8 years ago

Chrome 52.0.2743.116 (64-bit)

liftoff commented 8 years ago

I just commandeered my wife's Mac and can confirm this behavior. It appears to be a bug in Mac OS X itself since it is exhibited in Chrome, Firefox, and Safari. Essentially, the browser does not fire the keyup event if the command key is held at the same time. The only keyup event you'll get is for the command key itself.

I'll see if I can implement a workaround that resets the state of all keys held during a command+ keystroke on Macs (to prevent the hold event from misfiring) but I can't work around the fact that on Macs you'll never get that keyup event in these situations. So something like HI.on('command-c', doStuff) would work but if you also had a keyup:c event at the same time it would never get triggered if the command key was held during a combo.

Interestingly, this bug doesn't appear to effect the other modifier keys. So command-shift would work without issue.

lokhmakov commented 8 years ago

Ok

liftoff commented 8 years ago

I just pushed a commit that should fix this issue. Can you pull the latest code and confirm/deny?

lokhmakov commented 8 years ago

Yep, 1.1.13 fix this

http://jsbin.com/nodofoguza/edit?html,js,output

lokhmakov commented 8 years ago

But

After pressing only Enter and HI.pause() - HumanInput thinks that I hold Enter

Is still here

lokhmakov commented 8 years ago

Try it http://jsbin.com/kahusajica/1/edit?html,js,output

liftoff commented 7 years ago

OK I've finally got around to trying to test this on a Mac and I cannot reproduce it. Is this still happening? Here's what I've been using to test:

function onLeft() {
    console.log('LEFT')
}

function onEnter() {
    HI.pause();
    console.log('ENTER PAUSE');
}
HI.off('left'); HI.off('enter');
HI.on('left', onLeft);

HI.on('enter', onEnter);

Then I check HI.state to see if there's anything in the down or downAlt arrays but every time I test it they're both empty (as they should be). It doesn't think that the enter key is still held down.

I tested in Chrome and Safari on a Mac (no idea what version it was--only had it for a few minutes). What browser were you using?