Thursday, May 14, 2009

Create your own Konami code or custom code.

I have used Paul Irish code for my example.



<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script>

jQuery(function($){

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);
//Any message or event you want goes here
alert('The Konami Code Is Activated');
}
});
});
</script>



By replacing unicode char values in this line you can define any key combination you like.
Example
var kkeys = [], konami = "38,40,75";
this means up,down,k

You can find any key code from this site http://www.javascriptkit.com/jsref/eventkeyboardmouse.shtml

2 comments:

  1. Thanks for this, it was very helpful in creating a easter egg hunt on my site.

    ReplyDelete
  2. How can i change what it redirects to

    ReplyDelete