Skip to content

Instantly share code, notes, and snippets.

@mnylen
Created August 30, 2011 13:07
Show Gist options
  • Save mnylen/1180833 to your computer and use it in GitHub Desktop.
Save mnylen/1180833 to your computer and use it in GitHub Desktop.
var pressedKeys = {};
var tick = function(msDuration) {
gamejs.event.get().forEach(function(e) {
if (e.type == gamejs.event.KEY_DOWN) {
pressedKeys[e.key] = true;
} else if (e.type == gamejs.event.KEY_UP) {
delete pressedKeys[e.key];
}
});
for (var keyCode in pressedKeys) {
if (pressedKeys.hasOwnProperty(keyCode)) {
// Do something with the key
}
}
};
gamejs.time.fpsCallback(tick, this, 25);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment