Created
March 2, 2017 16:37
-
-
Save oodzchen/2e76a137a10d0238de2650e2005720b2 to your computer and use it in GitHub Desktop.
check multiple keys pressed at same time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.keysOnHold = []; | |
window.onkeydown = function(e){ | |
if(this.keysOnHold.indexOf(e.keyCode) < 0){ | |
this.keysOnHold.push(e.keyCode); | |
} | |
console.log(this.keysOnHold); | |
}; | |
window.onkeyup = function(e){ | |
this.keysOnHold.splice(this.keysOnHold.indexOf(e.keyCode), 1); | |
console.log(this.keysOnHold); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment