Konami Code jQuery Plugin: Pointlessly Easy

May 12, 2009

konami code

Everything old is new again.  The Konami Code is the most famous video game cheat of all time.  It began in 1986 with the original Nintendo system -- almost every game that the Konami company produced contained the code.  Eventually even games that were produced by other companies included the code.

Well in 2009 the code has seen a resurgence. ESPN, Facebook, and even Google Reader have all added Easter Eggs that are triggered by the Konami Code. A more comprehensive listing of the sites that have enabled the code is at konamicodesites.com. (Of course you must enter the code to see them!)

So if you want your site to get in on the retro action, we've put together a little jQuery plugin that makes it dead simple.

The Konami Code Plugin

To enable the code on your site, you just need to make a simple call and pass in the function you want executed.

$(window).konami(function(){ alert('Konami Code Activated!')});

The only advanced option available is the ability to switch from the default code to one of your choosing. Just pass in a comma-separated string of ASCII codes and it will run when they have been pressed. The following code would trigger when "n,m,c" is typed.

$(window).konami(function(){ alert('NMC Code Activated!')}, "78,77,67");

To see an example in action check out the demo.

You can also download a zip of the demo with the plugin.

Have fun and be sure to leave a link to your site with the code in the comments.

Update: The code in the zip file is now corrected as described in the comments.

Update 2 (8/2/2011): Philip's update from the comment to limit memory usage has been added.


Dan's avatar
Worked for me, thanks
Christo's avatar
kkeys = [];
Worked for me along with the bind fix :)
Gav's avatar
I still can't get the code to work multiple times (even after replacing "$(this).unbind..callee);" with "kkeys=[];"

Any ideas?
gorgonzolada's avatar
if you want to be able to use the code multiple times, replace this line:

$(this).unbind('keydown', arguments.callee);

with this:

kkeys = [];
Chris's avatar
It's an easy fix to get it to work with jQuery 1.6. Where you see the following at the end of the plugin code:

}, true);


Change it to:



et voila.
Ryan's avatar
It looks like this plugin doesn't work with the 1.6.x branch of jQuery. The following error occurs each time you press a key "j.handler.apply is not a function"
Rob's avatar
Rob NMC team member
It looks like this only lets you do it once. Is there anyway to have it reset kkeys when it is entered successfully?
Philip Peterson's avatar
Philip Peterson
This code will delete unnecessary old values from the array. It will limit the memory of past keystrokes to the number necessary in order to detect the code. It should go right after the push statement.

while (kkeys.length > code.split(',').length) {
Júlio Santos's avatar
Júlio Santos
Thanks man, check out http://whoisjuliosantos.com

James Morrish's avatar
James Morrish
Check out my konami at http://jamesmorrish.co.uk !
jay's avatar
There is an error with jQuery 1.6 "Object true has no method apply"

This is because the konami.js is using the wrong function signature for keydown.

Simply remove "true" as the second argument in the konami.js source on line 14, and this should fix it.
Jimmy Gunawan's avatar
Jimmy Gunawan
The code does not seem to work on IE as IE6, 7, 8. Maybe will work on IE9?

Works on Chrome, Firefox.
Mik's avatar
Does it collect every key press into kkeys array? Does it ever empty that array?

Would that be a problem if that was used on a game site where you could expect a lot of key presses over a long period of time?
Joel Sutherland's avatar
Joel Sutherland NMC team member

The code is now updated to work by default.
vaisselle porcelaine's avatar
vaisselle porcelaine
Still not fixed as of nov. 2010, so if you download this like I did, remember to check this
other than that thanks a lot for the nifty little function ^^
zobzz's avatar

yeah Adam, the demo doen't work, because there's a little problem about the key codes in the JS file

replace this :

by this :

Adam's avatar
Adam NMC team member

Your demo doesn't work with IE8. If you bind the event handler to the document, then it will work.

 David Bootle's avatar
David Bootle

There is a (deliberate?) error in the konami.js file in the .zip download.

Check the ASCII code list... the last one should be 65 (for A) - not 66 (B).

Leave a comment