HHi,
I’m writting a tetris game in Java/SWT.
When I hold down two keys, and then release one, that key release isn’t sent to my KeyListener.
Example: I hold down “drop”, I hold down “move left”, I let go of “drop”, I let go of “move left”.
We would expect that it would be neither dropping or moving left. However, it doesn’t stop dropping.
here’s my keyReleased code. It’s pretty simple, so I don’t think it’s the problem, but I’ll include it anyway.
public void keyReleased(KeyEvent e) {
int value = e.keyCode;
if( value == lMoveLeft ) game1.stopMovingLeft();
if( value == lMoveRight ) game1.stopMovingRight();
if( value == lDrop ) game1.stopDropping();
if( value == rMoveLeft ) game2.stopMovingLeft();
if( value == rMoveRight ) game2.stopMovingRight();
if( value == rDrop ) game2.stopDropping();
}
It was originally an if…else if… else if chain, but I took out the else’s to make sure those weren’t somehow causing the problem.
It’s not any of the function calls I’m making in there, because it never gets that far. ( I checked with printlns)
What’s most strange about this bug is that it doesn’t occur if I’m using the arrow buttons. I can hold as many as I want and release them however and it works exactly how I would expect.
It does happen when I use any letter key though. I haven’t tested for anything but the 4 arrows and the 26 letters.
Does anyone know how I can fix this? Is this a bug or a feature?
Any help is appreciated.