Created
April 8, 2015 11:29
-
-
Save julienetie/6dfb45ef49e3171912bf to your computer and use it in GitHub Desktop.
Key controls without conditions
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.addEventListener("keydown", function (e) { | |
var newKp = 'key' + e.keyCode, | |
keyID, | |
key = { | |
'key38': function () { | |
alert('up'); | |
}, | |
'key40': function () { | |
alert('down'); | |
}, | |
'key37': function () { | |
alert('left'); | |
}, | |
'key39': function () { | |
alert('right'); | |
}, | |
'key32': function () { | |
alert('space'); | |
}, | |
action: function (keyID) { | |
this[keyID](); | |
} | |
}.action(newKp); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment