Posted By


Sephr on 02/26/09

Tagged


Statistics


Viewed 40 times
Favorited by 2 user(s)

konamiCodeListener


/ Published in: JavaScript
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  1. function konamiCodeListener(func) {
  2. if ( window.addEventListener ) {
  3. window.addEventListener("keydown", function(evt){
  4. konamiCodeListener.keys.push(evt.keyCode);
  5. if ( konamiCodeListener.keys.toString().indexOf( konamiCodeListener.code.toString() ) >= 0 ) {
  6. konamiCodeListener.keys = [];
  7. func();
  8. }
  9. }, true);
  10. }
  11. }
  12.  
  13. konamiCodeListener.keys = [];
  14. konamiCodeListener.code = [38,38,40,40,37,39,37,39,66,65];

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.