Search code examples
javascriptkeyup

key sequence entering in javascript


i have this piece of javascript code

    keyPos = 0;
keySeq = [38,38,40,40,37,39,37,39,66,65];
keySeqUser = [];

var logKeys = function(evt) {
  key = evt.keyCode ? evt.keyCode : evt.which ? evt.which : evt.charCode;

  if (keyPos <= 9) {
    keySeqUser.push(key);
    keyPos++;
  } else {
    keySeqUser = [];
    keyPos=0;
  }
  if (keySeqUser.toString() == keySeq.toString()) {
    $(".page").hide();
    $(".lanes").fadeIn().animate({height: "600px"}, 2000);
    $(".pin").hide();
    setTimeout(function() {
      $(".pin").show().animate({opacity: 1}, 500);
    }, 2500);
    attemptKeyCombo();
  }
  console.log(keySeqUser.toString());
}

this webpage is hidden and in order to open it i should open it by pressing the same key combo which is stored within the variable keySeq, when i open the webpage and try to apply the same key combo [38,38,40,40,37,39,37,39,66,65] which is in ASCII to text editor translates into &&((%'%'BA, i have tried to do that but the console only stores one key stroke per time, that means i can't press shift + 7 in order to type the symbol &.

when i press a key that ascii value of the key pressed is stored within the keySeqUser and when the value of that variable equals the value of the keySeq the webpage opens, i have no idea on how to solve this problem, i would appreciate any help and thanks!.

note: i am checking the value from the browser's console console.log()


Solution

  • when I translated ASCII characters into normal characters and searched for them I found that they represent Konami code.