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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
JuiletteCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.