How to stop repeated keyPressed() / keyReleased() events in Swing?

So the problem that I am having appears to be a bug that occurs only on Linux Yes this is a Linux problem On Windows when a key is held down you get multiple KeyPressed events but only a single KeyReleased event This question is asked often and I've never seen a good solution But I think the basis of a solution is to use a Timer. When the key is pressed you start a Timer. When you get another keyPressed you restart the Timer.So as long as the Timer interval is greater than the repeat rate of the key board the Timer will be continually reset when a key is held down.

When keyPresses stop being generated the Timer will fire so you assume the key has been released. This implies you will have a delay in processing the keyReleased.

So the problem that I am having appears to be a bug that occurs only on Linux Yes this is a Linux problem. On Windows when a key is held down you get multiple KeyPressed events but only a single KeyReleased event. This question is asked often and I've never seen a good solution.

But I think the basis of a solution is to use a Timer. When the key is pressed you start a Timer. When you get another keyPressed you restart the Timer.So as long as the Timer interval is greater than the repeat rate of the key board the Timer will be continually reset when a key is held down.

When keyPresses stop being generated the Timer will fire so you assume the key has been released. This implies you will have a delay in processing the keyReleased.

Here's the bug from Sun (includes sample work-arounds): bugs.sun.com/view%5Fbug.do?bug%5Fid=4153069.

This question is duplicated here. Here's a hack implemented as an AWTEventListener that can be installed at the start of the application.

Java - How to stop repeated keyPressed() / keyReleased() events in Swing - Stack Overflow.

You can find a pretty good workaround here.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions