title: Java input stops working when window is unfocused
body: <p>today I added keyboard input to my game the way I always do, with <code>KeyListener</code>, but for some reason, in my program whenever I click outside of the window and click back in, the key input just stops working. Here is what I have in my <code>keyPressed</code> and <code>keyReleased</code> methods:</p>
  
  <pre><code>public void keyPressed(KeyEvent e) {
  
      int code = e.getKeyCode();
  
      switch (code) {
      case KeyEvent.VK_W:
          keys[0] = true;
          break;
      case KeyEvent.VK_D:
          keys[1] = true;
          break;
      case KeyEvent.VK_S:
          keys[2] = true;
          break;
      case KeyEvent.VK_A:
          keys[3] = true;
          break;
      }
  }
  
  public void keyReleased(KeyEvent e) {
  
      int code = e.getKeyCode();
  
      switch (code) {
      case KeyEvent.VK_W:
          keys[0] = false;
          break;
      case KeyEvent.VK_D:
          keys[1] = false;
          break;
      case KeyEvent.VK_S:
          keys[2] = false;
          break;
      case KeyEvent.VK_A:
          keys[3] = false;
          break;
      }
  }
  </code></pre>