I have the following code in a game I am programming:
public void keyReleased(KeyEvent e) {
int key = e.getKeyCode();
if (key == KeyEvent.VK_SPACE) {
doIShoot = false;
}
}
public void keyPressed(KeyEvent e) {
int key = e.getKeyCode();
if (key == KeyEvent.VK_SPACE) {
shoot();
}
}
public void shoot(){
if(!doIShoot){
doIShoot = true;
// code that creates bullet
}
}
It is intended that the player must press the button for every bullet, it shouldn't automatically shoot when he holds space. In Windows that works just fine, but in Ubuntu Linux, it doesn't. It seems that when i hold space, it will always execute keyReleased and keyPressed alternately.
Why is Ubuntu doing this, and how can I make it work?
Edit:
I just found this: How to stop repeated keyPressed() / keyReleased() events in Swing
Edit2:
A Solution: http://brunez.net63.net/tutorials/keypressfix/keypressfix.php