How to press 2 keys at once?
Author |
Message |
Reality Check
|
Posted: 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
|
|
|
OneOffDriveByPoster
|
Posted: 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
|
Posted: 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. |
|
|
|
|
|
|
|