trapping function keys

Can anyone tell how i can do something when F12 key is pressed. It seems it cannot be trapped in KeyPress event like the other keys using the ASCII code. Please help
ahmed021399Asked:
Who is Participating?
 
HobbitHouseConnect With a Mentor Commented:
put this in a text box keydown:

Private Sub txtReceiver_KeyDown(KeyCode As Integer, Shift As Integer)
    MsgBox "got key with code = " & CStr(KeyCode)
    If KeyCode = 123 Then MsgBox "what do you mean there's no F12?"
End Sub


0
 
Éric MoreauSenior .Net ConsultantCommented:
The KeyPress event is only good for trapping ASCII characters (letters, numbers, punctuation, delete, enter, back, ...)
0
 
aikimarkCommented:
When possible, use the intrinsic constants (keycode in this case) for clearer code.  

vbKeyF12 = &h7B = 123


0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
Richie_SimonettiIT OperationsCommented:
If yopu need to trap F12 key in entire form, first set Heypreview property of form to true, after that use some like this:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
if KeyCode=vbkeyf12 then
  Debug.Print KeyCode
end if
End Sub
0
 
MonchangerCommented:
This might be overkill, but it will capture that key you want. It's actually meant to capture keys outside (as well as inside) your application.

http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=24607&lngWId=1

Since you want to use F12, I guess it wouldn't really hurt other applications.
0
 
Richie_SimonettiIT OperationsCommented:
Where you read:
"If yopu need to trap F12 key in entire form, first set Heypreview "
it must be:
"If you need to trap F12 key in entire form, first set KeyPreview "
Sorry.
0
 
aikimarkCommented:
Isn't "Heypreview" a lot like Caller-ID? :-)
0
 
Richie_SimonettiIT OperationsCommented:
:))
0
 
ahmed021399Author Commented:
Richie your code is just for the active application, right?
0
 
Richie_SimonettiIT OperationsCommented:
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.