Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Programming KeyPress Events for Function keys

Status
Not open for further replies.

JCG4LOM

Technical User
Jul 10, 2003
18
0
0
US
I would like to program a keypress event so that when a function key is pressed the click event is kicked off. Basically,

1. User presses F9
2. Program interperts Keypress and calls a click event of a command button found on the form.

I am having trouble interperting the keypress as a function key. I have code that can determine ASCII characters, but I would really like to map to a function key.

Hopefully, someone may be able to help.

Jason
 
Unfortunately, the KeyPress event does not fire for the function keys (and some other keys), but you can use the KeyDown event. (Be sure that the KeyPreview property of the form is set to Y)
Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

   If ((KeyCode >= 112) And (KeyCode <= 123)) Then
      MsgBox &quot;Function Key Pressed:  F&quot; & Trim(KeyCode - 111)
      KeyCode = 0
   End If

End Sub


Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top