title: Javascript keydown: checking both for arrows and the minus sign, work-around for Firefox
body: <p>I am developing a web application with javascript in which</p>
  
  <ul>
  <li>if the right arrow is pressed, we go to the next level.</li>
  <li>if the minus sign is pressed, we reduce the difficulty.</li>
  <li>if the space bar is pressed, we pause.</li>
  </ul>
  
  <p>Because I want to check for arrows as well, I can't use the keypress event, so instead I'm using the keydown event. A simplified section of code (using jQuery) is the following.</p>
  
  <pre><code>$(document).keydown(dealWithKeyDown);
  function dealWithKeyDown(evt) {
      if (evt.which == 39) // Right arrow.
          nextLevel();
      if (evt.which == 189) // Minus sign.
          reduceDifficulty();
      if (evt.which == 32) // Space.
          pause();
  }
  </code></pre>
  
  <p>The problem I'm having now is that it doesn't work in Firefox. In FF the keycode for the minus sign is 173 instead of 189. (And there are more differences like that.) Can anyone suggest an easy/elegant work-around?</p>
  
  <p>The easiest work-around I can think of is to use the 'evt.key' property, but 'evt.key' is undefined in Chrome, while for the space button IE gives 'evt.key == "Spacebar"' as true while Firefox gives 'evt.key == " "' as true. It's an inconsistency nightmare.</p>