Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 How to press 2 keys at once?
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Reality Check




PostPosted: Wed May 30, 2007 7:38 am   Post subject: How to press 2 keys at once?

I'm having problems getting two keys to be pressed at once. Its either one or the other. Thanks in advanced.
Sponsor
Sponsor
Sponsor
sponsor
OneOffDriveByPoster




PostPosted: Wed May 30, 2007 7:46 pm   Post subject: Re: How to press 2 keys at once?

We cannot help you unless if you tell us what you are using to read the keys and what your program is supposed to do.
aramadia




PostPosted: Wed May 30, 2007 9:46 pm   Post subject: RE:How to press 2 keys at once?

You have to attach a KeyListener which I assume you already did. Then create an array of boolean[256] and set it to true when the key is pressed, and set it to false when the key is released. Then, simply check if any of the key values is true to determine if the key is down.

You can also and a FocusListener to set all keys to false when the user clicks somewhere else. You can also make some kind of one time system which ensures that holding a key doesn't do 100 presses while you tap it if you are running a game loop.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: