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!

FKey to fire Button event

Status
Not open for further replies.

stonee74

Technical User
Nov 12, 2001
49
CH
Hi guys,

I did a script containing a button to execute a specific action. At the moment I use as the caption of the button &UP to be able to use shortrcut Alt-U.
I would prefer using F9 Key instead, is there a slim way to do that, or do i really need to implement a message mechanism which waits for key events?
thanks for any and all help,
stonee
 
Set KeyPreview on the form to True

In the Form_KeyDown event capture the key pressed:

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

If KeyCode = vbKeyF9 Then
'do something
End If

End Sub
 
thanks,
looks simple..
on my form there are about 10 controls on that form, i guess sometimes i loose the focus and cannot receive those key events...

Case vbKeyF9:

txt_setPID.Text = s_incID(txt_setPID)
status = o.SetPointId(CurrentStation, txt_setPID.Text, "comment")
Form1.SetFocus
...
any ideas?

thanks again,
stonee
 
stonee ..
Since KeyPreview is a form level event, it should not matter what control on the form has the focus, or how many controls you have on it, If the keyPreview property is set to true and your code is the proper syntax, it should capture that keypress. to make sure it is running that procedure, you could do something as simple as add this into your form Key_Down event.
If KeyCode = vbKeyF9 then
Print "you pressed F9"
.. (your existing code here)
Print "F9 KeyCode event finished"
Else
Print KeyCode
End If
Doing this will atleast tell you if you have the keycode captured.
Also why are you setting the focus on the form instead of on a control on that form? If Form1 is the only one loaded, it never lost focus.
HTH
Michael
 
stonee ...
I just re-read my post and instead of
..(your existing code here)
you could from there use
Call (your Button)_Click()
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top