Konami Code

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");
  
  }

});

Comments

  1. User Avatar
    Russ
    Permalink to comment#

    You misspelled Konami.

    :-)

    -Russ

  2. User Avatar
    Josh
    Permalink to comment#

    Such a good idea :D

  3. User Avatar
    Johnny
    Permalink to comment#

    30 lives!

  4. User Avatar
    Rowe
    Permalink to comment#

    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.

    • User Avatar
      Kim
      Permalink to comment#

      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.

  5. User Avatar
    Michael Beckwith
    Permalink to comment#

    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

  6. User Avatar
    nicolas
    Permalink to comment#

    I couldn’t figure what is it?? What is this for?

Posting Code

You may write comments in Markdown. This makes code easy to post, as you can write inline code like `<div>this</div>` or multiline blocks of code in triple backtick fences (```) with double new lines before and after.

Code of Conduct

Absolutely anyone is welcome to submit a comment here. But not all comments will be posted. Think of it like writing a letter to the editor. All submitted comments will be read, but not all published. Published comments will be on-topic, helpful, and further the discussion or debate.

Want to tell us something privately?

Feel free to use our contact form. That's a great place to let us know about typos or anything off-topic.

Submit a Comment

icon-closeicon-emailicon-linkicon-menuicon-searchicon-tag