title: KeyListener not working the way I want it to for arrow keys?
body: <p>I am making a the snake game and I have implemented the KeyListener class that listens to when the user presses the arrow keys or WASD keys.</p>
  
  <p>In snake, when you press a movement key, the snake will continue to move if you just press a movement key once, and will only go in another direction once you enter a different movement command. However, in my program I have to hold the key down for the snake to move, I can't just press it once. How do I make it so that I just have to press the key once to move the snake?</p>
  
  <p>Also, the WASD keys are working differently than the arrow keys. When I press a WASD key, the snake only moves one block and then stops, unlike the arrow keys where the snake moves as long as I hold down the arrow keys. How do I make the WASD keys work the same way as I want the arrow keys to work?</p>
  
  <p>Here is the code:</p>
  
  <pre><code>public void keyTyped(KeyEvent e) {
  }
  
  public void keyPressed(KeyEvent e) {
      if (e.getKeyCode() == KeyEvent.VK_LEFT || e.getKeyCode() == KeyEvent.VK_A) {
          out.println("Left key pressed");
          // handle snake left movement
      } else if (e.getKeyCode() == KeyEvent.VK_RIGHT || e.getKeyCode() == KeyEvent.VK_D) {
          out.println("Right key pressed");
          // handle snake right movement
      } else if (e.getKeyCode() == KeyEvent.VK_UP || e.getKeyCode() == KeyEvent.VK_W) {
          out.println("Up key pressed");
          // handle snake up movement
      } else if (e.getKeyCode() == KeyEvent.VK_DOWN || e.getKeyCode() == KeyEvent.VK_S) {
          out.println("Down key pressed");
          // handle snake down movement
      }
  }
  
  public void keyReleased(KeyEvent e) {
  }
  </code></pre>