Secret Hidden message on keyboard enter

Just had a thought and was wondering if it was possible in the spirit of april fools.

Is it possible to have a secret code that you randomly type in a website similar to that on a gaming console like (a, up, down, b, L1, R1), but on the website, you would type on your keyboard "9 2 k (uparrow) 3" and as long as you're on the website, it does something, let's say alert('hey')? Curious to see how you would do it.

Answers 1

  •   // our combo
      var combo = [57, 50, 75, 38, 51];
    
      var keys = new Array(combo.length);
      $(document).on('keydown', function(evt){
        // remove the earliest of the stored keys
        keys.shift();
        // push in the latest key pressed
        keys.push(evt.which);
    
        // compare with combo array - you could use any comparison method (convert to string,...)
        if (!keys.some(function(e, i) { return e !== combo[i] }))
          alert('hey')
      })
    

    Fiddle - https://jsfiddle.net/kzj5e7Lk/

    You'll need to click in the run area (bottom right pane) before you try the key combination.


Related Articles