PDA

View Full Version : Buffer of Excess Key Presses in Java ?



jaypaul
05 Jun 2009, 09:24 AM
Hi Friends,

I've started one game project and there is, if the user presses a key multiple times the actions will be performed as many times as it registers, even though I disallow key presses during the time that the action is taking place.

For example, a move of 1 space can be carried out with a key press. While the character is moving, key presses are not allowed. However, if you just press the key 5 or 25 times, the character will just keep moving, once he's done with the first one.

What I need to do is clear the buffer of key presses after an action has taken place, so that the excess keys are not registered. I know the commands to do so in C++, but not in Java.

Your Answers'll be Helpful.

Thanks,
Paul

chaines51
05 Jun 2009, 10:24 AM
How exactly are you handling this?
Could you possibly post the current code here, because, AFAIK, Java doesn't use a buffer. It detects the key press, and sends it to all related action listeners, regardless of what else is going on.