My GeneralKeyInput class enables key repeat.
http://jasel.cvs.sourceforge.net/jasel/jasel2.input/src/jasel2/input/GeneralKeyInput.java?view=markup
Each time I poll the Keyboard, I do
356 if (keyRepeat) {
357 for (int i = 0; i < keyTimeouts.length; ++i) {
358 if (keyTimeouts[i] == NOT_DOWN)
359 continue;
360
361 if (keyTimeouts[i] > 0) {
362 keyTimeouts[i] -= millis;
363 }
364
365 if (keyTimeouts[i] <= 0) {
366 buffer.add(i, keyChars[i]);
367 keyTimeouts[i] += repeatRate;
368 }
369
370 }
371 }
keyTimeOuts is just a giant int[], one for each key on the keyboard. When a key is first pressed, I enter the repeat rate in millis in its corresponding keyTimeOuts index. Then each cycle i subtract the amount of elapsed millis from it. If it goes < 0, then it’s time to “fire” another key event for that key, in my case that means just adding it to the keys pressed buffer.
It’s not as efficient as I’d like, but I only enable key repeat for when the user is typing, and generally that’s at a low impact part of the game like entering a high score.
That’s the gist of it anyway. There is more going on in the class, like the initial repeat event is longer, to simulate what typically happens in typing (press and hold down a key, the second letter won’t appear for a bit, then they rapidly repeat from there)