Capturing F Keys

How do i capture an F Key? I want to be able to run a function on the keypress of a key say F4.
hutchisonAsked:
Who is Participating?
 
JuiletteConnect With a Mentor Commented:
Create a project with a blank form and paste the following code :-
Option Explicit

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyF1: MsgBox "F1 pressed."
Case vbKeyF2: MsgBox "F2 pressed."
Case vbKeyEscape: MsgBox "ESC"
End Select
End Sub

Private Sub Form_Load()
Form1.KeyPreview = True
End Sub


0
 
VbmasterCommented:
One solution would be to set the KeyPreview property of the form to True, then you can intercept any key in the KeyDown/KeyUp event. The F keys are defined as constants (vbKeyF1 -> vbKeyF12).
0
 
VbmasterCommented:
One solution would be to set the KeyPreview property of the form to True, then you can intercept any key in the KeyDown/KeyUp event. The F keys are defined as constants (vbKeyF1 -> vbKeyF12).
0
 
VbmasterCommented:
Sorry for the double post, both my personailities want to contribute.
0
 
hutchisonAuthor Commented:
vbMaster yours was exactly the same as well when i hit accept answer i didn't see who was the accepted answer. Both work the same.
0
All Courses

From novice to tech pro — start learning today.