title: Make a KeyEvent in Java only happen once even when key is held
body: <p>I need to know if it is possible to have an action only happen once when a key is pressed, even if that key is held down for some time, and if it is possible, how?
  This is the code I have for that now: </p>
  
  <pre><code>if(e.getKeyCode() == KeyEvent.VK_A)
  {
     attack = true;
     moveX = -5;
     draw(moveX, moveY);
     players.get(username).setImageIcon("attack-left"); 
  }
  </code></pre>
  
  <p>This is within the keyPressed method, and in the keyReleased I set moveX to 0. So if A is pressed the image is supposed to 5 units to the left and stop, regardless of whether or not A is still being held down or it has been released. But this is not working, it just keeps on moving to the left. I tried using keyTyped but it didn't work.</p>
  
  <p>Thanks in advance, and if needed I can provide more code.</p>