title: How to calculate time interval between two "keyup" events
body: <p>i need to create some kind of elementary pos with javascript. I have an barcode scanner that work like a keyboard. So i want to automaticaly detect when the input come from the barcode and then create a report with that codes. I think an good idea is to calculate the difference of typing speed because the scanner is really fast: </p>
  
  <pre><code>if there a dalay between keyup &gt; 300ms = another scan
  
  var speed = new Date().getTime() - lastkey;
      lastkey = (new Date()).getTime();
          console.log(speed);
      if(speed &gt; 300) {
          //little delay for prevent computer overhead o_O
          var create_d = setTimeout(createchange,300)
          } else {
          //barcode sanning continue
          clearTimeout(create_d)
      }
  </code></pre>
  
  <h1><a href="http://jsfiddle.net/StartStep/sbWH9/12/" rel="nofollow">JsFiddle link &lt;</a></h1>