title: jQuery keydown CRLF
body: <p>I have a problem with the jQuery keydown parameters. I use a Barcode Scanner which sends a 12char string and a CR LF at the end. So I would expect the ASCII code 13 for the last call of keydown. What I get is a additional 40 -> 13 40 (CR "(").
  In other applications like Notepad++ / C# console applications etc. the CR is recognized as last character.
  Here's a sample code:</p>
  
  <pre><code>var keys = [];
  
  $(document).keydown(function (e) {
      keys.push(String.fromCharCode(e.which));
  });
  
  $(document).keyup(function () {
      if(keys.length == 14)
      {
          handleCode();
      }
  });
  
  function handleCode() {
      var div = document.getElementById('out');
      var html = '';
      var numberOfKeys = keys.length;
      //Last 2 keys == CR "("
      for (var i=0; i &lt; (numberOfKeys);i++) {
          html += keys[i];
      }
      div.innerHTML = html;
      keys = [];
  }
  </code></pre>
  
  <p>Has anyone an idea why there's an additional "(" (ASCII code 40) at the end?</p>
  
  <p>Edit: I figured out following behavior for a scanner output of "12345CR":</p>
  
  <pre><code>Event on TextBox: 
  KeyDown: 49 50 51 52 53 13 ('12345CR')
  KeyPress: 49 50 51 52 53 13 ('12345CR')
  KeyUp: 49 50 51 52 53 13 40 ('12345CR(')
  
  Event on Document:
  KeyDown: 49 50 51 52 53 13 40 ('12345CR(')
  KeyPress: 49 50 51 52 53 13 ('12345CR')
  KeyUp: 49 50 51 52 53 13 40 ('12345CR(')
  </code></pre>
  
  <p>I end up using KeyPress, which works just fine when it's attached to document (I thought it only works on textboxes). But I still wonder, where the 40 ('(') come from.</p>
  
  <p>Here's the updated code, which works fine now:</p>
  
  <pre><code>var keys = [];
  var startTime;
  
  $(document).keypress(function (e) {    
      keys.push(String.fromCharCode(e.which));
      if(keys.length == 13)
      {
          handleCode();
      }
  });
  
  function handleCode() {
      var div = document.getElementById('out');
      var html = '';
  var numberOfKeys = keys.length;
      for (var i=0; i &lt; (numberOfKeys);i++) {
          html += keys[i];
      }
      div.innerHTML = html;
      keys = [];
  }
  </code></pre>