title: Do something on key hold and on keyup
body: <p>I need to call function:</p>
  
  <ol>
  <li><p>Every second when key is hold (e.g. for five seconds of holding it should fire 5 times every second).</p></li>
  <li><p>When user releases key (<code>keyup</code>) and if less then one second passed.</p></li>
  </ol>
  
  <p>Events should be binded on document, not on text input.</p>
  
  <p>If second statement "kinda" works, with first I have problems as keypress event isn't working on some browsers and keydown fires event all the time.</p>
  
  <pre><code>var interval;
  $(document).on('keypress', function(e) {
      console.log('keypress');
  
      interval = setInterval(function() {
          doSomething(e.keyCode);
      }, 1000);
  
  }).on('keyup', function(e) {
      console.log('keyup');
  
      if(interval === 0) {
          doSomething(e.keyCode);
      }
      clearInterval(interval);
      interval = 0;
  });
  
  
  function doSomething(keyCode) {
       console.log(keyCode);
  }
  </code></pre>
  
  <p>jsFiddle: <a href="http://jsfiddle.net/kWFUA/" rel="nofollow">http://jsfiddle.net/kWFUA/</a></p>
  
  <p>Thank you for help!</p>