hello!
is there a method or class that lets you assign events to the keys of your keyboard (spacebar to fire gun)? and is there a way to measure how long the key was held down? thanks!!! any help is greatly appreciated.. ive tried google-ing it but i had no luck in looking for a class/method that does those things =) tnx
Re: Measure or detect how long a button was help down
KeyListener Using keyListener
You need to implement it, and then add a listener with addKeyListener(this) and you need to use all of the methods provided because it is a interface (they are listed in the link I gave you.) The second link should help you learn how to use it. Using Google you could find the key codes for each of the keys on the keyboard.
Last edited by jasimp; Aug 23rd, 2008 at 12:13 pm.
Re: Measure or detect how long a button was help down
Why not store the current time in a data type (like a long) when the key is pressed and when the key is released subtract the new time from the old time?
Re: Measure or detect how long a button was help down
Why not store the current time in a data type (like a long) when the key is pressed and when the key is released subtract the new time from the old time?
To make this work simply focus the pane (by clicking it) and key events will be listened for. Hold down a key then when you release it the seconds the key was held down will be displayed.
Last edited by Alex Edwards; Aug 24th, 2008 at 12:54 am.
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.