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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

key press event in commandgroup button 3

Status
Not open for further replies.

cgc22

Programmer
Jan 17, 2007
10
US
Hi,
I'm using VFP 9.0 and am not savy on how to use "events"
within a command button that have code as follows:

KEY PRESS EVENT: LPARAMETERS nKeyCode, nShiftAltCtrl

If I have a commandgroup button (com1 & com2)
CAPTION ON COM1: "CLICK TO CONTINUE SEARCH FOR CUSTOMER-No"
CAPTION ON COM2: "CLICK HERE IF THIS IS THE CUSTOMER-Yes"
?? to search .DBF file

If I want the USER to NOT have to use the mouse to "click"
on the command for each seperate command button, but instead just press the "N" key for NO or press the "Y" key for yes. Do I use the KEY PRESS EVENT for this? If so, what
code should I write for Lparameters, Nkeycode ETC. for
KEY "N" or "Y". Once I set the focus to the Commandgroup
button ? I'm used to the old foxpro 2.6 code "IF ANS = "Y"
etc. Any help would be greatly appreciated.
Greg
 
Yes you can use the KeyPress
for nKeyCode,nShiftAltCrl see the help on inkey() it gives you the ASC number for the keyboard keys

However the command messagebox() would do better in this case. Just my Opinion.


David W. Grewe Dave
 
Put hot keys i.e.
*** Captions:
CLICK TO CONTINUE SEARCH FOR CUSTOMER \<No
CLICK HERE IF THIS IS THE CUSTOMER- \<Yes

But make sure no other control on the form has Y or N as hot keys
 
Greg,

Yes, you can use the Keypress event for this, but it has to be the Keypress of the form, not of the command group. If that were not so, the key would only work while the command group or a command button has focus.

You will also need to set the form's KeyPreview property to .T.

In the form's Keypress, your code will look something like this:

Code:
LPARAMETERS nKeyCode, nShiftAltCtrl

DO CASE
  CASE nKeyCode = ASC("N") OR ASC("n")
    * user clicked N
    * ----
  CASE nKeyCode = ASC("Y") OR ASC("y")
    * user clicked Y
  
  * and so on
ENDCASE

Imaginecorp suggested placing hot keys (AKA accelerators) on the command buttons. That would work well, except that the user would have to hold down Alt when typing the keys.

Hope this helps.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Hi Greg,

Be advised that if you use Mike's solution and you have a textbox where the user might need to enter the letters 'n' or 'y' that when they do so it will also fire the code in the form's keypress event.
If the form requires any data entry you will need to be able to determine whether the keystroke is intended to trigger the command button action or is intended to be data entry.

pamela
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top