Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eliminating Initial keypress delay

When you type into a textbox and hold a key, you get (a.......aaaaaaaaaaaaaaa), depending on the initial key press delay.

addKeyListener(new KeyAdapter() {
    public void keyPressed(KeyEvent e) {
        // Handle key press here
    }

I'm creating a game in which the user's reflexes are very important. How can I eliminate this delay completely? The above code does not work. I have also tried overriding processKeyEvent with no luck.

like image 400
David Avatar asked Sep 24 '11 07:09

David


Video Answer


1 Answers

These events are generated by the JVM / operating system, and unless you instruct the user to change the key-delay / key-repeat settings I'm afraid you'll have to do some more work.

I suggest you create a Timer which fires events in the correct rate, start and stop the timer upon keyPressed / keyReleased.

like image 97
aioobe Avatar answered Sep 29 '22 20:09

aioobe