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!

KeyPress Event & Ctrl+Right Arrow?

Status
Not open for further replies.

diarmaid

Programmer
Jun 27, 2003
34
IE
I can't seem to detect when Ctrl+Right Arrow keyboard combination is pressed.

In the following nKeyCode & nShiftAltCtrl are the same whether you press Crtl+RightArrow or Ctrl+F ? Also, in the VFP9 Help I notice that INKEY() has a Ctrl value of "2" for both Ctrl+B key press and Ctrl+RightArrow key press.

Any enlightenment ?

CASE nKeyCode=27 && ESC was pressed
thisform.Release

CASE nKeyCode==1 AND nShiftAltCtrl==2 && Ctrl + Left
thisform.btnPrevious.Click

CASE nKeyCode==2 AND nShiftAltCtrl==2 && Ctrl + Right
thisform.btnNext.Click

CASE nKeyCode==6 AND nShiftAltCtrl==2 && Ctrl + F
thisform.btnSearch.Click

CASE nKeyCode == 107 && Alt + F4
thisform.btnExit.Click
 
Diarmaid

I do similar keytrapping in my forms. To test for keys I have a form called SHOWANSI. It is a blank form with the command ? LASTKEY in the KEYPRESS event. To test for control keys I changed it to:
LPARAMETERS nKeyCode, nShiftAltCtrl
? LASTKEY()
? nKeyCode
? nShiftAltCtrl

It says that :
CTRL LEFT ARROW nKeyCode = 26 and nShiftAltCtrl = 2
CTRL RIGHT ARROW nKeyCode = 2 and nShiftAltCtrl = 2

Also make sure that you have the form's KEYPREVIEW property set to TRUE

I hope this helps

Jim Rumbaugh
 
I'm not seeing the same as either of you.

I get 2 for Ctrl+Right and 26 for Ctrl+Left.

Actually, it varies according to whether you are using the numeric keypad or the cursor keypad. And if you're using the numeric keypad, it depends on whether NumLock is on.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
First is the forms keypreview set to .t. and is your code in the keypress event?
for Ctrl + f you do not need to read the "nShiftAltCtrl" as the combination of Ctrl + f = 6

CASE nKeyCode = 6 && Ctrl + f
thisform.btnSearch.Click()
 
Imaginecorp - that is true, however the End key also returns 6 so you would need to test nShiftAltCtrl to see which key/combination the user pressed.

I get the following:
Code:
             nKeyCode  LASTKEY()
Ctrl+f     :    6         6
Ctrl+Right :    2         2
Ctrl+b     :    2         2
Ctrl+Left  :   26        26

So LASTKEY() is actually LASTKEYCOMBINATION

Is there then a way to tell between Ctrl+b and Ctrl+Right??

Stewart
 
Stewart: You have me stumped. We do not use lastkey() etc

You are right:
Ctrl+b is the same as Ctrl+Right.so how do you tell which key was pressed.I am sure there is a way.

To make matters worse, Ctrl+b opens the Breakpoint pane for me.
I could get the Ctrl+f to work by using just nKeyCode.

This has got me intrigued, will work on it the minute I have some time and will report back.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top