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

trap key press in MDI window 1

Status
Not open for further replies.

petevick

Technical User
Jul 25, 2001
131
0
0
GB
Hi, does any one know how to trap a key press in a MDI window, I'm trying to detect when the F1 key has been pressed.
 
Hi,

You could try trapping the keypress in the Form_KeyDown() Event

Example:

Private Sub Form_KeyDown(KeyCode as Integer, Shift as Integer)

If KeyCode = vbKeyF1 Then

'write your code for the event here....

End If

End Sub

Good luck!
 
Sorry, I also forgot to mention to set the KeyPreview = True in the form's properties!
 
Thanks for the replies Griffinator, unfortunatly a MDIForm has neither the KeyDown event or the KeyPreview property, werein lies my problem. I'm guessing that I'll finish up with an API call.
 

Option Explicit
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer

and add a timer. Set it's interval to something like 50.
And use:

Private Sub Timer1_Timer()
If GetAsyncKeyState(vbKeyEscape) < 0 Then
Debug.Print &quot;Got it!&quot;
End If
End Sub
 
Nice one CCLINT, that works a dream, have a star
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top