ahmed021399
asked on
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The KeyPress event is only good for trapping ASCII characters (letters, numbers, punctuation, delete, enter, back, ...)
When possible, use the intrinsic constants (keycode in this case) for clearer code.
vbKeyF12 = &h7B = 123
vbKeyF12 = &h7B = 123
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
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
if KeyCode=vbkeyf12 then
Debug.Print KeyCode
end if
End Sub
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.
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.
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.
"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.
Isn't "Heypreview" a lot like Caller-ID? :-)
:))
ASKER
Richie your code is just for the active application, right?
yes, if you need to trap from others:
http://www.freevbcode.com/ShowCode.Asp?ID=1610
and a related one:
http://www.freevbcode.com/ShowCode.Asp?ID=1308
http://www.freevbcode.com/ShowCode.Asp?ID=1610
and a related one:
http://www.freevbcode.com/ShowCode.Asp?ID=1308