I’m writing a game in Java, right now it’s Swing + JOGL – a JFrame with a GLCanvas.
I handle input using keyPressed etc. events (jframe.addKeyListener(...)) and it doesn’t seem to work properly:
when I have 3+ keys down at the same time, they don’t register properly– apparently this is keyboard’s fault, I have to find an alternate control scheme.- after the window loses, then regains focus, input stops working completely…
What am I doing wrong?
Is there a better way of handling keyboard input in Java?
(I’d rather not switch to another library, like LWJGL… unless I have no choice).
To keep dependencies down, I would go for the “built-in” keyboard handling. It works just fine if you know what your doing. I’ll paste some code from my games:
It handles key-repeats with custom repeat-delay / rate and has no issues with in which component keyboard focus lies.