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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable Function (F) Keys Using VB 1

Status
Not open for further replies.
Jun 2, 2004
66
US
I would like to disable all of the F keys, in particular the F1, F7 and F12 keys. I have tried the code (see below), but it is not working properly. I'm not sure whether or not to use the code on the KeyPress or KeyDown Event. If I decide to use the OnKeyPress, I would need the Ascii code for the F keys. I have found Ascii code maps online, but I'm just not sure which code to use.


Here is the code I tried on On KeyDown..... No luck...

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If ((KeyCode = vbKeyF12) Or (KeyCode = vbKeyF7)) Then

KeyCode = 0

End If
End Sub


Here is the On KeyPress that I tried, but I don't know what to plug in for the F key Ascii codes.

Private Sub Form_KeyPress(KeyAscii As Integer)
If ((KeyAscii = ??) Or (KeyAscii = ??)) Then

KeyAscii = 0

End If
End Sub




Would either of these methods work, or am I going in the wrong direction with this? I have read about setting up Macros to trap these functions, but I would rather stay away from Macros if possible.
 
Did you set the form KeyPreview property to Yes?

If not, try that and the KeyDown event should work.

Hope this helps.

OnTheFly
 
Have you tried using an "AutoKeys" macro to override these keys and tell them to do "nothing"?

Just a thought.

ProDev, MS Access Applications
Visit me at ==>
May God bless you beyond your imagination!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top