You should never handle movement or position changes directly in the KeyListener methods.
Never do something like
if keycode = key_left
x_position -= 10;
Especially while a key is pressed, the result can differ depending on the computer, because the frequence of keypress events differs with different hardware. I made this error too in a Pong Clone. I inserted code moving the paddle directly in the listener and the paddle was too slow in my notebook because the keypressed event was not sent often enough.
So what you do is use flags that go true / false. For ordinary “while pressed” actions like moving, you just set a boolean true when the key gets pressed and set it false when the key is released. In the game logic loop, you check this flags and do movement (position change) if true. For other actions you can need a “has been pressed” funcionality. Functions like Pause, Menu, Quicksave, etc should work when the key has been pressed once, even if it has already been released. You dont want the game to go pause while p is pressed but if the user presses and releases p you gou pause.
You can use easy logic, this would be, set the flag true when the key is released and set it false when the game logic reads it. A more difficult logic sets the pause true already on keypress not on release, but if the logic reads it and sets it to false, it must remain false even if the key is still pressed. It may only be set true again if the key has been released. You need two booleans for this.
Some games only react on key release with this buttons, other games react on keypress but do not go like autofire when you keep it pressed. Otherwise you would go pause on/off all the time while you keep it pressed. You want pause or menu to switch on for the first press, and only disappear after a second distinct press, not just on a repeated pressed event beacause the key is still pressed.
Using this, you can also handly multiple key presses. Just read the flags for left right up down and react. Usually, left/right and up/down should be different forces in your game that are independent. For topdown, left and right would change x-velocity and up and down would change y-velocity, without each caring about the other. For a simulation of a plane or car its the same. The game logic doesnt notice if up AND left is pressed. They modify different forces.
-JAW