Created
January 15, 2011 23:17
-
-
Save jaz303/781358 to your computer and use it in GitHub Desktop.
Key State
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> | |
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js'></script> | |
<script type='text/javascript'> | |
var states = {}; | |
// w - 87 | |
// a - 65 | |
// s - 83 | |
// d - 68 | |
$(document).bind('keydown', function(evt) { | |
states[evt.which] = true; | |
}).bind('keyup', function(evt) { | |
states[evt.which] = false; | |
}); | |
setInterval(function() { | |
var state = ""; | |
if (states[87]) state += "FWD "; | |
if (states[83]) state += "BACK "; | |
if (states[65]) state += "LEFT "; | |
if (states[68]) state += "RIGHT "; | |
if (state.length) { | |
console.log(state); | |
} | |
}, 500); | |
</script> | |
</head> | |
<body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment