Youre right.
If I remember, its KDE wich fires these KeyPressed/KeyReleased event for autorepeat.
You can use something like this to know how long a key has been hold down :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| protected long leftKeyTimer = 0; protected long leftKeyFinalTimer = 0;
if (leftKeyTimer == 0) { leftKeyTimer = System.currentTimeMillis(); } leftKeyFinalTimer += (System.currentTimeMillis() - leftKeyTimer); leftKeyTimer = 0;
if (leftKeyTimer != 0) { leftKeyFinalTimer += (System.currentTimeMillis() - leftKeyTimer); leftKeyTimer = System.currentTimeMillis(); } long leftTime = leftKeyFinalTimer; leftKeyFinalTimer =0;
|
The thing is you cant rely on key release event to know when a key has been really released. If it has not been really released, a keyPress event is fired right after the KeyRelease one.
So you might also try to wait sonething like 10ms (you should check how really close in time these 2 events are fired) when you receive a keyRelease event before processing it and cancel it if a keyPress event is received during this time.
Regards,
Charly