Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Timeout ? Keypress/Interactive Change

Status
Not open for further replies.

networkthis

Programmer
Jul 11, 2011
29
US
I'm trying to create a timeout after each keypress(that can't be seen) - but if it is interrupted by another keypress I need it to cancel the timeout.

I know that you can do this:

- wait window "" timeout .5 and not see the wait window
- wait clear - clears the screen
- that pressing a key cancels the timeout
- and that pressing a key on the wait window doesn't immediately give me a lastkey() value in the keypress event

- that assigning a variable to the wait window like this:
wait window to myVar "" timeout .5
- and then later calling myVar that I can get the value of the key that closed the window

This seems so simple, but the more I try this the more confused I become!


 
If you really want a "timeout after a keypress", then none of the WAIT commands are what you want.

What you really need is a timer object, firing every second, incrementing your "seconds since last keystroke" property of the form. In Keypress, you set that "seconds since last keystroke" back to 0 because a key was just pressed.

Either the timer or the form's Keypress method can be used to detect when the timeout interval has been reached and act as desired.

You're correct that Lastkey() is useless in Keypress() because if you issue NODEFAULT in Keypress() the keystoke is "swallowed". The keystoke hasn't "registered" yet. BUT, keypress (assuming you've set the form's KeyPreview property) receives the same keycode as a parameter.

It's easier to do than to describe. :)
 
Thanks Dan you made my life much easier with that advice!!!

For the record... It's great being the new guy sometimes!!! hmmmmm.... Maybe I should have read 1002 Things about Fox Pro instead

Anyways, now that I know this, I can't wait to make some cool things with it! Btw... this was super, super easy to do with the timer.

I put the timer itself to .F.
Then simply set the timer to .T. on the keypress event that I wanted to start the timer and then - magic!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top