Skip to content

Instantly share code, notes, and snippets.

@oodzchen
Created March 2, 2017 16:37
Show Gist options
  • Save oodzchen/2e76a137a10d0238de2650e2005720b2 to your computer and use it in GitHub Desktop.
Save oodzchen/2e76a137a10d0238de2650e2005720b2 to your computer and use it in GitHub Desktop.
check multiple keys pressed at same time
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