title: Detect keypress combination series with Javascript
body: <p>For the Easter holiday, I'm wanting to have a little surprise &quot;Easter Egg Hunt&quot; on a site I develop for. Two of these five <em>Easter Eggs</em> I'm hiding will be keypress ordained. This won't be like a &quot;Press CTRL and TAB at the same time&quot; type deal but will be a &quot;Pres UP three times and then RIGHT three times&quot; type of thing. This will be looking for a series of keypresses instead of just two pressed at once. I've got this function set up, but for some odd reason it isn't working like it should.</p>
  <p><b>NOTE:</b> The script below is looking for the following keypress series:<br>
  surprise1 - LEFT (x3), RIGHT (x3), UP (x3), DOWN (x3)<br>
  surprise2 - SHIFT (x3), TAB (x3), CTRL (x3)</p>
  <pre><code>$(document.body).keydown(function(e) {
              surprise1(e);
              surprise2(e);
  });
  
  function surprise1(e) {
      var ev = (e) ? e : window.event;
      var k = ev.keyCode;
      if (k &gt; 36 &amp;&amp; k &lt; 41) {
          typekeys[k] = isNaN(typekeys[k]) ? 0 : typekeys[k];
          typekeys[k]++;
          if (typekeys[37] == 3) {
              if (typekeys[37] == 3 &amp;&amp; typekeys[39] == 3) {
                  if (typekeys[37] == 3 &amp;&amp; typekeys[39] == 3 &amp;&amp; typekeys[38] == 3) {
                      if (typekeys[37] == 3 &amp;&amp; typekeys[39] == 3 &amp;&amp; typekeys[38] == 3 &amp;&amp; typekeys[40] == 3) {
                          alert(&quot;You've found Surprise 1! Contact the site admin ASAP to get your prize!&quot;);
                          typekeys[37] = typekeys[39] = typekeys[38] = typekeys[40] = 0;
                      }
                  } else {
                      typekeys[40] = 0;
                  }
              } else {
                  typekeys[38] = typekeys[40] = 0;
              }
          } else {
              if (typekeys[37] &gt; 3) {
                  typekeys[37] = 0;
              }
              typekeys[39] = typekeys[38] = typekeys[40] = 0;
          }
      } else {
          typekeys[37] = typekeys[39] = typekeys[38] = typekeys[40] = 0;
      }
  };
  
  function surprise2(e) {
      var ev = (e) ? e : window.event;
      var k = ev.keyCode;
      if (k &gt; 8 &amp;&amp; k &lt; 18) {
          typekeys[k] = isNaN(typekeys[k]) ? 0 : typekeys[k];
          typekeys[k]++;
          if (typekeys[16] == 3) {
              if (typekeys[9] == 3) {
                  if (typekeys[16] == 3 &amp;&amp; typekeys[9] == 3 &amp;&amp; typekeys[17] == 3) {
                      alert(&quot;You've found Surprise 2! Contact the site admin ASAP to get your prize!&quot;);
                      typekeys[16] = typekeys[9] = typekeys[17] = 0;
                  }
              }
          } else {
              if (typekeys[16] &gt; 3) {
                  typekeys[16] = 0;
              }
              typekeys[9] = typekeys[17] = 0;
          }
      } else {
          typekeys[16] = typekeys[9] = typekeys[17] = 0;
      }
  };
  </code></pre>
  <p>Mind telling me exactly as to why that isn't working? It seems like to me it should work.</p>