Created
September 14, 2011 04:51
-
-
Save tamalw/1215877 to your computer and use it in GitHub Desktop.
JavaScript key bindings
This file contains hidden or 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
<html> | |
<head> | |
<title>JS Key Example</title> | |
<script type="text/javascript"> | |
addEventListener("keydown", function (e) { | |
var output = document.getElementById('output'); | |
if (e.keyCode == 37) { | |
output.innerHTML = "You pressed left." | |
} | |
if (e.keyCode == 38) { | |
output.innerHTML = "You pressed up." | |
} | |
if (e.keyCode == 39) { | |
output.innerHTML = "You pressed right." | |
} | |
if (e.keyCode == 40) { | |
output.innerHTML = "You pressed down." | |
} | |
}, false); | |
</script> | |
</head> | |
<body> | |
<h1 id="output"></h1> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment