title: Handling WASD and Arrows simultaneously in JavaScript game
body: <p>Let's assume the simple pong game for two players with one keyboard.</p>
  
  <p>The movement handler appears to be easy:</p>
  
  <pre><code>document.addEventListener('keydown', function (event) {
          if (event.keyCode === 87) { //w
              movePaddle(leftPaddle, 0);
  
          } else if (event.keyCode === 83) { //s
              movePaddle(leftPaddle, 1);
  
          } else if (event.keyCode === 38) { //arrow_up
              movePaddle(rightPaddle, 0);
  
          } else if (event.keyCode === 40) { //arrow_down
              movePaddle(rightPaddle, 1);
  
          }
  });
  </code></pre>
  
  <p>The second argument in <code>movePaddle</code> function just means the direction (up or down).</p>
  
  <p>The problem: if <code>W</code> and <code>Up Arrow</code> are pressed together, then only one paddle moves. It depends on which key were pressed last.</p>
  
  <p>How to handle keydown events correctly? </p>
  
  <p>I need two paddles moving together according pressed keys. If <code>W</code> and <code>Up Arrow</code>, then both go up. If <code>W</code> and <code>Down Arrow</code>, then left goes up and right goes down. Of course, only one paddle should move if only one key are pressed.</p>