I'm writing a game in Java 3D and am currently trying to implement movement of my character using the WASD keys. It works fine when one key is pressed at a time - you can move forwards, backwards, or turn left or right, but if you try to walk forwards AND turn, the latter keypress is ignored. The problem seems to be that it ignores key press events if a key is already pressed; I told it to print out every time a key is pressed or released, and when a key is already held down, the second key is not reported as being pressed, but it is reported as released. The code takes the following structure: private void procKeys(AWTEvent[] events) { for (int n = 0; n < events.length; n++) { if (events[n] instanceof KeyEvent) { KeyEvent k = (KeyEvent) events[n]; if (k.getID() == KeyEvent.KEY_RELEASED) { System.out.println(k.getID() + ", " + k.getKeyChar() + " released"); ... } else { k.getKeyChar() + " pressed"); ... } If anyone can advise me how I can handle these simultaneous events I would be very grateful, Thanks
|