Key Press F1

charityg

Registered User.
Local time
Today, 02:28
Joined
Apr 17, 2001
Messages
634
I need to code a procedure to run when the user presses F1 while in a particular field. What is the corresponding value for F1? Is this as easy as it seems?
OnKeyPress
If (this is the part I'm not sure about) then
MyProcedure
End If
 
Don't you have to use SendKeys for this? reliability problems aside if you re-assign F1 it won't open help file.
HTH
 
In MSDN I found something under "ToolsCustomizeKeyboard" which is actually a function in VB. It lists the value of F1 as 112.

From help:

Syntax
Private Sub Form_KeyPress(KeyAscii As Integer) or Private Sub controlname_KeyPress(KeyAscii As Integer)


KeyAscii
Returns a numeric ANSI key code. The KeyAscii argument is passed by reference; changing it sends a different character to the object. Changing the KeyAscii argument to 0 cancels the keystroke so that the object doesn’t recognize that a key was pressed.


You can convert the KeyAscii argument to a character by using the following expression.

Chr(KeyAscii)

You can then perform string operations and translate the character back to an ANSI number that the control can recognize by using the following syntax.

KeyAscii = Asc(character)

So, if I read this correctly, your statement would be something like:

OnKeyPress
If KeyAscii = 112 then
MyProcedure
End If

Matt
 

Users who are viewing this thread

Back
Top Bottom