Advertisement
Guest User

Untitled

a guest
May 25th, 2015
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. /*!
  2. * SimpleKonami
  3. * Copyright: WTFPL
  4. * Version: 1
  5. * Requires: jQuery v1.3.2 or later
  6. */
  7.  
  8. //Set up our array of needed keys, and variables.
  9. neededkeys = [38,38,40,40,37,39,37,39,66,65], started = false, count = 0;
  10. $(document).keydown(function(e){
  11. key = e.keyCode;
  12. //Set start to true only if having pressed the first key in the konami sequence.
  13. if(!started){
  14. if(key == 38){
  15. started = true;
  16. }
  17. }
  18. //If we've started, pay attention to key presses, looking for right sequence.
  19. if(started){
  20. if(neededkeys[count] == key){
  21. //We're good so far.
  22. count++;
  23. } else {
  24. //Oops, not the right sequence, lets restart from the top.
  25. reset();
  26. }
  27. if(count == 10){
  28. //We made it! Put code here to do what you want when successfully execute konami sequence
  29.  
  30. //Reset the conditions so that someone can do it all again.
  31. reset();
  32. }
  33. } else {
  34. //Oops.
  35. reset();
  36. }
  37. });
  38. //Function used to reset us back to starting point.
  39. function reset() {
  40. started = false; count = 0;
  41. return;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement