var kkeys = [], konami = "38,38,40,40,37,39,37,39,66,65";
$(document).keydown(function(e) {
kkeys.push( e.keyCode );
if ( kkeys.toString().indexOf( konami ) >= 0 ) {
$(document).unbind('keydown',arguments.callee);
// do something awesome
$("body").addClass("konami");
}
});
Konami Code
Chris Coyier
on
You misspelled Konami.
:-)
-Russ
Such a good idea :D
30 lives!
Is this like an easter egg? … can the user just type the “code” anywhere / anytime the window is active? … if you have a minute, can you give a more fully formed example of a use case or some explanatory text on configuring this function. Thanks! Very cool.
I’m not the author of this function, but this is probably just for easter egg fun given the nature of the “real” Konami code. The method is being called on the document, so yes, it should work “anywhere” as long as the window is active.
As for use cases, just Google “Konami code” or see an article roundup like this one: http://mashable.com/2010/07/31/konami-code-sites/ for examples of this type of thing being used.
I know this has floated around for awhile as I found it myself elsewhere on the internet. It’s not exactly efficient code. It tracks all keystrokes you make and if it’s on a site that you’re doing a lot of typing on, that could add up to a lot of js memory use. Granted most of the time, it’d probably be on a site that you’re just viewing.
You can see my attempt to rewrite it, in a much more lightweight efficient way here:
https://github.com/tw2113/WordPress-Starter-Theme/blob/master/js/konami.js
Awesome. You should note however where to put the code to run after the key combination was successfully entered, took me some debugging to figure out that it is under
if (count == 10) {
.I couldn’t figure what is it?? What is this for?