I'm having problems figuring out how to get properly notified when keys are pressed. The keyPressed
method doesn't seem to be called again for the first key pressed when handling multiple keys.
Example: if I press the right arrow key and hold onto it, it gets called repeatedly (keeps printing test). But if I press the right arrow key, then press space key once, while holding onto the right arrow key, as soon as the space key is released, the keyPressed()
method doesn't seem to be called. (nothing being printed).
This is what my code looks like:
public void keyPressed(KeyEvent e) {
System.out.println("test");
switch (e.getKeyCode()) {
case KeyEvent.VK_LEFT:
guy.moveLeft();
break;
case KeyEvent.VK_RIGHT:
guy.moveRight();
break;
case KeyEvent.VK_SPACE:
guy.jump();
break;
}
}