Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Microsoft: FoxPro FAQ

Forms & Screen

KEYPRESS Event instead of ON KEY LABEL by jimoo
Posted: 1 Sep 03 (Edited 19 Oct 03)

As developers, we have a tendency to use what worked for us in the past.  Overall, there is nothing wrong with this, as long as it still works efficiently, but sometimes we need to change.

Using the ON KEY LABEL for FoxPro 2.6 forms worked pretty well and generally returned the desired results.  However, using the ON KEY LABEL in an object environment is a different story.  A better approach to using ON KEY LABEL on forms is the KEYPRESS Event.

First Example
You have a form and you wish to recalculate all values (must run a program or method) when the user presses the F9 key.  If you look in the help (under INKEY) you will see all the key values.  F9 has a value of -9.

Step 1.
Set the KEYPREVIEW property on the form to .T.

Step 2.
Add the following code in the form KEYPRESS event.
  DO recalc.prg

Second Example
You have a login form (or a search form) and you want it to click the [Ok] button after the user presses [Enter] on the password text-field.  The default behavior is skipping to the [Ok] button, and then you need to press [Enter] a 2nd time.  In addition, you wish to trap to see if the user pressed the [Escape] key on the text-field, and click the [Cancel] button for them if so.

Step 1 is the same.
Set the KEYPREVIEW property on the form to .T.

Step 2
Add the following code in the KEYPRESS event of the password textbox:
  * Enter Key
  * Escape Key

Back to Microsoft: FoxPro FAQ Index
Back to Microsoft: FoxPro Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close