title: Reliable arrow key input in javascript
body: <p>I need to detect arrow key input in javascript. Currently I am doing this:</p>
  
  <pre><code>document.onkeydown = function(event) {
      if (event.which == 37) {
          ...
      } else if (event.which == 39) {
          ...
      } else if (event.which == 38) {
          ...
      } else if (event.which == 40) {
          ...
      }
  };
  
  document.onkeyup = function(event) {
      if (event.which == 37) {
          ... 
      } else if (event.which == 39) {
          ...
      } else if (event.which == 38) {
          ...
      } else if (event.which == 40) {
          ...
      } 
  };
  </code></pre>
  
  <p>This works fine, but when i press command + right and release the arrow key first, I get the down event for the arrow key, but only get an up event when releasing the command key. Also the keycode is 91 regardless of which arrow key I was pressing. How do I handle this situation?</p>
  
  <p>I am on a mac with google chrome.</p>