title: jQuery: Listening for automated scanner input from keyboard?
body: <p>I'm writing a web app for a library system with a barcode scanner attached. The scanner's input presents as keyboard input, and it's always of the form <code>~~[\d]+.[\d]+~~</code>, for example <code>~~470.002~~</code>.</p>
  
  <p>I want to set up a jQuery listener for scanner input, and am a jQuery novice. It should listen to all keyboard input, but only perform an action when it hears input from the scanner, and only when the scanner input has finished.</p>
  
  <p>This is as far as I've got (i.e. not very):</p>
  
  <pre><code>//Global functions: call on all pages.
  $(document).ready(function() {
      // Listen for scanner input. 
      $(window).keypress(function(e) {
          var key = e.which;
          if (key==126) {.
              alert('tilde');
              // How to listen for the correct input?
              // check_out_book();
          }
      });
  });
  </code></pre>
  
  <p>What's the best way to keep listening input in the format I need? I'd like it to listen for the final two tildes before calling <code>check_out_book()</code>. </p>
  
  <p>I'd also like it to 'stop' listening after the first tilde if there is a pause - to distinguish between a human typist and the automated scanner input. Does jQuery have a way to do this?</p>
  
  <p>Any pointers very much appreciated! Thank you. </p>