Computing.Net > Forums > Programming > Java simultaneous key presses

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Java simultaneous key presses

Reply to Message Icon

Name: neal
Date: December 22, 2008 at 05:17:46 Pacific
OS: vista business SP1 32 bit
CPU/Ram: athlon64x2 6000+/4GB
Product: - / -
Comment:

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



Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Java simultaneous key presses

Simultaneous kbd events www.computing.net/answers/programming/simultaneous-kbd-events/12783.html

Multiple key presses in JavaScript www.computing.net/answers/programming/multiple-key-presses-in-javascript/10927.html

C#.NET - ENTER key press on DataGri www.computing.net/answers/programming/cnet-enter-key-press-on-datagri/8701.html