ehgoodenough / keyb

Poll the state of the keyboard.
https://www.npmjs.com/keyb
3 stars 1 forks source link

When multi-pressing a combo like "CMD+Z", the letter Z still registers as pressed even after release #6

Open DLMcPherson opened 9 months ago

DLMcPherson commented 9 months ago

For example, the check for an undo hotkey:

if(Keyb.isPressed("<meta>") && Keyb.wasJustPressed("Z"))

successfully registers the first combo input, but then after releasing and pressing again it still doesn't work. Adding a flag to an AND of isPressed like:

if((Keyb.isPressed("<control>") || Keyb.isPressed("<meta>")) && Keyb.isPressed("Z")) { if(this.hasJustUndone == false) { console.log("UN") this.hasJustUndone = true this.loadProtoUnitsToUndo() } } else { this.hasJustUndone = false }

again successfully registers the first combo input, and then messes up the second. In this configuration it prematurely fires the "CMD+Z" even when only the "CMD" is depressed. When checking multiple hotkeys (like both UNDO and REDO) after they've both registered correctly once, they will thereafter both fire at the same time whenever CMD is hit all by itself (canceling each other out in this instance).

Further testing by logging the state of Keyb.data["Z"] on the above code snippet reports that Keyb thinks the Z key is still depressed even when hitting only the CMD key: image

ehgoodenough commented 8 months ago

I reproduced this bug! For whatever reason, the browser does not trigger the keyup event of a key if you follow it by or . The keyup event for and will trigger, but not the key you pressed before it.

Thinking how to debug this now.

ehgoodenough commented 8 months ago

https://stackoverflow.com/questions/11818637/why-does-javascript-drop-keyup-events-when-the-metakey-is-pressed-on-mac-browser