In the playground above, if you hit ‘Command + c’, then the copy function is triggered as expected BUT when I release all keys and then just press ‘Command’ the copy function is fired again.
Why is the state of the ‘c’ key being reset to 1 in this case?
I’d like the ‘c’ key to be reset to 0 when I release all keys, so then on my next input changed observable I’m back in my original state. (No keys pressed)
Okay, so I’m able to repro this on my Mac. Lemme take a look and see what’s going on. I suspect that the CMD+C combo is somehow preventing the keyup event from being registered, which is why the C is still showing as active. I’ll need to confirm this though.
My limited investigation shows that IF a keydown event for a non-modifier key (a, b, c, etc) has metaKey = true, then you will never see the keyup event for that key…
Hmmm, this maybe bigger than Babylon - looking at the MDN docs for KeyboardEvent.key and typing into KeyboardEvent sequence example I never see the keyup for a key that was typed while Meta (Command) was held down on a Mac in Chrome at least…
Okay, well, I hope someone proves me wrong but I believe this is Mac OS default behavior that cannot be fixed (not receiving the keyup event for a key pressed while Meta was held down):
@PolygonalSun Wow, thanks for the quick fix for this issue. As an aside, during my exploration of the problem, I did notice that keyup events were fired when focusing/clicking off the browser. Weirdly though, the keyup events don’t look the same as the normal IKeyboardEvent. Specifically they are missing the code property of the normal Keyboard event (KeyboardEvent.code - Web APIs | MDN)
The below shows what I received when doing Command + V in the browser: