Samooramad
asked on
key stroke time limit
hi experts,
I need a bit of code for an if statement that waits for a key press for 5 seconds.. and if a key is not pressed in that time it does something
thanks
I need a bit of code for an if statement that waits for a key press for 5 seconds.. and if a key is not pressed in that time it does something
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i do use a key listner if thats what you mean
> i do use a key listner if thats what you mean
then delay adding it for 5 seconds
then delay adding it for 5 seconds
ASKER
how do I do that?
the code i posted above is one way to achieve it, you could also use a Timer.
ASKER
objects, does your code add the listner more than once?
no, it just delays adding it for 5 seconds.
ASKER
maybe I needed to be more clear..or Im not quite understanding this.
I want to add a keylistner to a component (thats done) then have the option of either pressing one key or pressing two.
so after the first key is pressed the program waits for 5 seconds and if another one hasnt been pressed then it is assumed that only one key was pressed and so on for other components. Does your code still apply to that?
sorry if I'm being a pain :)
I want to add a keylistner to a component (thats done) then have the option of either pressing one key or pressing two.
so after the first key is pressed the program waits for 5 seconds and if another one hasnt been pressed then it is assumed that only one key was pressed and so on for other components. Does your code still apply to that?
sorry if I'm being a pain :)
in that case store the time the first key is pressed, and compare the difference when the second key is pressed.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
the variable t must, of course, be global...
ASKER
how objects?
thanks newnemis :) I'm working on your code will let u know if I get it working or not
thanks newnemis :) I'm working on your code will let u know if I get it working or not
ASKER
nesnemis, how do I declare t?
Thread t; ??
Thread t; ??
Yes; Thread t;
=)
[r.D]
=)
[r.D]
ASKER
how do you check if a key was pressed during the 5 seconds?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
*woops, I think you need to declare the bPressed as public, like so:
public boolean bPressed = false;
=)
public boolean bPressed = false;
=)
ASKER
thanks everyone for the help
8-) ThanQ
ASKER
whats the difference?