Skip to content

Instantly share code, notes, and snippets.

@btipling
Created February 12, 2014 16:37
Show Gist options
  • Save btipling/8959266 to your computer and use it in GitHub Desktop.
Save btipling/8959266 to your computer and use it in GitHub Desktop.
var f = document.body.onkeydown;
var flyStraight = 700;
var flyDown = 800;
var flyUp = 500;
var current = 500;
function run () {
window.setTimeout(function () {
console.log("current", current);
f();
run();
current = flyStraight;
}, current);
}
run();
function handle (evt) {
console.log("got key", evt.keyCode);
// "u"
if (evt.keyCode === 85) {
console.log("flying down");
current = flyDown;
}
// "d"
if (evt.keyCode === 68) {
current = flyUp;
console.log("flying up");
}
}
document.body.onkeydown = handle;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment