Using the KeyDown event

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all

I'm trying to get a message box to appear when a user presses a certain key when in a certain control. I start by assigning some code to the KeyDown event for that control.

Problem is, I don't know how to test for a particular key being pressed (in this case F1). This should be simple, but the Help files don't appear to cover it.

Please tell me what the code to test what key is being pressed is. Is it:

If (vbKeyF1 = True) Then
If (vbKeyF1 > 0) Then

or something else?

Whatever I've tried so far, the event (and therefore the code) is triggered when any key is pressed, rather than only if the F1 key is pressed.

Please help me out!

Thanks

David
 
The KeyDown event provides an argument named KeyCode. Try:
If KeyCode = vbKeyF1 Then

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

David Cleave said:
Hi all

I'm trying to get a message box to appear when a user presses a certain
key when in a certain control. I start by assigning some code to the KeyDown
event for that control.
Problem is, I don't know how to test for a particular key being pressed
(in this case F1). This should be simple, but the Help files don't appear to
cover it.
Please tell me what the code to test what key is being pressed is. Is it:

If (vbKeyF1 = True) Then
If (vbKeyF1 > 0) Then

or something else?

Whatever I've tried so far, the event (and therefore the code) is
triggered when any key is pressed, rather than only if the F1 key is
pressed.
 
Oh I see now!

Thank you

David

Allen Browne said:
The KeyDown event provides an argument named KeyCode. Try:
If KeyCode = vbKeyF1 Then

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.


key when in a certain control. I start by assigning some code to the KeyDown
event for that control.
(in this case F1). This should be simple, but the Help files don't appear to
cover it.
triggered when any key is pressed, rather than only if the F1 key is
pressed.
 
Back
Top