title: KeyListener for multiplayer game with keys being pressed at the same time?
body: <p>I am writing a Two Player snake game. The Arrow Keys respond to one snake and the WASD Keys respond to the other. However I have noticed in my code that if one key for each snake is pressed at the same exact time only one snake turns. I have two KeyListeners that contain an array of the four keys it should be responding to . </p>
  
  <pre><code>class PlayerKeyPressListener implements KeyListener {
  
      // Set of currently pressed keys
      private final Set&lt;Integer&gt; pressed; 
      private int keyEvent[];
      private Color c;
      private int i;
  
      public PlayerKeyPressListener(int[] a, Color col, int i) {
          super();
          pressed = new HashSet&lt;Integer&gt;();
          keyEvent = a;
          c = col;
          this.i = i;
      }
  
  
      @Override
      public void keyPressed(KeyEvent e) {
          if(!(pressed.contains(keyEvent[0]) || pressed.contains(keyEvent[1]) 
                  || pressed.contains(keyEvent[2]) || pressed.contains(keyEvent[3])))
              pressed.add(e.getKeyCode());
          proccessKey(e.getKeyCode());
      }
  
      @Override
      public void keyReleased(KeyEvent e) { 
          pressed.remove(e.getKeyCode());
      }
  
      @Override
      public void keyTyped(KeyEvent e) {/* Not used */ }
  
      public void proccessKey(int key){
          if(canTurn[i]) {    
              int d = grid.getDirection(c);
              if(key == keyEvent[0]) {
                  if(d == 360)
  
                      grid.setDirection(d - 90, c); //Sets the direction of the snake with the specified color 
                  else if(d == 180)
                      grid.setDirection(d + 90, c);
              }
              else if(key == keyEvent[1]) {
                  if(d == 360)
                      grid.setDirection(d + 90, c);
                  else if(d == 180)
                      grid.setDirection(d - 90, c);
              }
              else if(key == keyEvent[2]) {
                  if(d == 90)
                      grid.setDirection(d - 90, c);
                  else if(d == 270)
                      grid.setDirection(d + 90, c);
              }
              else if(key == keyEvent[3]) {
                  if(d == 90)
                      grid.setDirection(d + 90, c);
                  else if(d == 270)
                      grid.setDirection(d - 90, c);
              }
              canTurn[i] = false;
          } 
      }
  }
  </code></pre>
  
  <p>Heres is where they get constructed: </p>
  
  <pre><code>int[] a = {KeyEvent.VK_LEFT, KeyEvent.VK_RIGHT, KeyEvent.VK_UP, KeyEvent.VK_DOWN};
      int[] b = {KeyEvent.VK_A, KeyEvent.VK_D, KeyEvent.VK_W, KeyEvent.VK_S};
      this.addKeyListener(new PlayerKeyPressListener(a, Color.blue, 0));
      this.addKeyListener(new PlayerKeyPressListener(b, Color.red, 1));
  </code></pre>
  
  <p>Is there a way to make it more responsive for two players? </p>