Skip to content

Instantly share code, notes, and snippets.

@omichelsen
Last active August 29, 2015 13:56
Show Gist options
  • Save omichelsen/8861701 to your computer and use it in GitHub Desktop.
Save omichelsen/8861701 to your computer and use it in GitHub Desktop.
JavaScript keySequence
function keySequence(callback) {
var i = 0;
var konami = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65];
$(document).keydown(function (event) {
if (konami[i] === event.which) {
i++;
if (konami.length === i) {
i = 0;
callback();
}
} else {
i = +(konami[0] === event.which);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment