Link to home
Start Free TrialLog in
Avatar of Samooramad
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
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Samooramad
Samooramad

ASKER

>> gui or non-gui?

whats the difference?
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
how do I do that?
the code i posted above is one way to achieve it, you could also use a Timer.
objects, does your code add the listner more than once?
no, it just delays adding it for 5 seconds.
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 :)
in that case store the time the first key is pressed, and compare the difference when the second key is pressed.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
the variable t must, of course, be global...
how objects?
thanks newnemis :) I'm working on your code will let u know if I get it working or not
nesnemis, how do I declare t?
Thread t;   ??
Yes;  Thread t;
=)
[r.D]
how do you check if a key was pressed during the 5 seconds?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
*woops, I think you need to declare the bPressed as public, like so:

public boolean bPressed = false;

=)
thanks everyone for the help
8-)  ThanQ