Grow your CSS skills. Land your dream job.

Last updated on:

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. Permalink to comment#

    You misspelled Konami.

    :-)

    -Russ

  2. Josh
    Permalink to comment#

    Such a good idea :D

  3. Johnny
    Permalink to comment#

    30 lives!

  4. 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.

    • 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. 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:

    http://github.com/tw2113/WordPress-Starter-Theme/blob/master/js/konami.js

  6. nicolas
    Permalink to comment#

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

Leave a Comment

Posting Code

  • Use Markdown, and it will escape the code for you, like `<div class="cool">`.
  • Use triple-backticks for blocks of code.
    ``` 
    <div>
      <h1>multi-line block of code</h1>
      <span>be cool yo.</span>
    </div>
    ```
  • Otherwise, escape your code, like <code>&lt;div class="cool"&gt;</code>. Markdown is just easier though.

Current ye@r *

*May or may not contain any actual "CSS" or "Tricks".