/ Published in: JavaScript
Adds the `konamiCodeListener` function.
Syntax: `void konamiCodeListener(function)`
Every time the Konami Code (up,up,down,down,left,right,left,right,b,a) is entered, the function passed to konamiCodeListener will be called.
Syntax: `void konamiCodeListener(function)`
Every time the Konami Code (up,up,down,down,left,right,left,right,b,a) is entered, the function passed to konamiCodeListener will be called.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function konamiCodeListener(func) { if ( window.addEventListener ) { window.addEventListener("keydown", function(evt){ konamiCodeListener.keys.push(evt.keyCode); if ( konamiCodeListener.keys.toString().indexOf( konamiCodeListener.code.toString() ) >= 0 ) { konamiCodeListener.keys = []; func(); } }, true); } } konamiCodeListener.keys = []; konamiCodeListener.code = [38,38,40,40,37,39,37,39,66,65];