Some keyboards βchordsβ (simultaneous keystrokes) will not be correctly registered in the browser (tested by Chrome and Firefox). For example, using the code below, try the following:
1) press the "e" key (it will record "key 69")
2) while holding "e", press "]" (it will record "key 221")
3) while still holding βeβ and β]β, press βiβ (this will not work!)
4) however, if you go down to βiβ and press βoβ instead, it will successfully register βkey 79β.
document.onkeydown = function(event){ var key = event.keyCode; console.log("key", key); };
Can someone explain what is going on here and if there is some workaround? For context, I am developing a QWERTY based music application, and I would like to play all my chords.
I know that keyCode out of date, maybe this behavior is one of the reasons?
What is the correct approach to this problem?
Demo here: https://jsfiddle.net/nt0ad2ap/
source share