How do you trap for F1 key 
Author Message
 How do you trap for F1 key

I wrote a custom help for my application and can invoke it using a menu.  I
would also like to invoke the help program using the customary F1 key.

I placed the following code on the form's keypress but nothing happens.

If KeyAscii = vbKeyF1 Then
    mnuHelp_Click()
End If

I even tried this too but there is no response.  What am I doing wrong? and
where do I put the code?

If KeyAscii = 112 Then
    mnuHelp_Click()
End If

Maurice I. Muoneke



Sun, 19 Nov 2000 03:00:00 GMT  
 How do you trap for F1 key

You can set Form.KeyPreview property to True at design time
then you don't have to trap KeyDown in every control, just in  the
Form_KeyDown event.

Hope this helps.
Keith Baugher

Quote:

> However, as far as I know (I've tried it myself), you can't trap it any
> other way, except if you put code in the KeyDown event in every control on
> the form.



Sun, 19 Nov 2000 03:00:00 GMT  
 How do you trap for F1 key

You can easily get the F1 key to activate if you put it as a shortcut in
your menu.

However, as far as I know (I've tried it myself), you can't trap it any
other way, except if you put code in the KeyDown event in every control on
the form.

But.. as I said.. put a shortcut to it in the menu, and it will be
accessible from allover the form.

/Daniel




Mon, 20 Nov 2000 03:00:00 GMT  
 How do you trap for F1 key

Make sure the form's "KeyPreview" parameter is set to True,
and use the KeyDown event (or KeyUp event) instead of the
KeyPress event. Also, ensure you clear the KeyCode to 0 to
prevent Windows from continuing to process the key.

Sub myForm_KeyDown (KeyCode as Integer, Shift as Integer)
    If KeyCode = vbKeyF1 Then
        KeyCode = 0
        mnuHelp_Click
    End If
End Sub



Mon, 20 Nov 2000 03:00:00 GMT  
 How do you trap for F1 key

Set the form.KeyPreview property to True then trap for Keycode 112 in the
KeyDown event of the form.

Quote:

>You can easily get the F1 key to activate if you put it as a shortcut in
>your menu.

>However, as far as I know (I've tried it myself), you can't trap it any
>other way, except if you put code in the KeyDown event in every control on
>the form.

>But.. as I said.. put a shortcut to it in the menu, and it will be
>accessible from allover the form.

>/Daniel





Mon, 20 Nov 2000 03:00:00 GMT  
 How do you trap for F1 key

Hi

If you set the form's KeyPreview to True the key press will go to the form
first then the object so you will be able to trap keys for the entire form
with one bit of code in the keypress event.

Regards , Rob

Quote:

> You can easily get the F1 key to activate if you put it as a shortcut in
> your menu.

> However, as far as I know (I've tried it myself), you can't trap it any
> other way, except if you put code in the KeyDown event in every control on
> the form.

> But.. as I said.. put a shortcut to it in the menu, and it will be
> accessible from allover the form.

> /Daniel





Sat, 25 Nov 2000 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Trapping F1 key

2. Q: Trap F1 key in MDI main form?

3. How to trap F1 key for process

4. Trapping F1 Key for entire Process

5. Why does SS Tab trap key events before the form traps them

6. How trap F1?

7. KEY (Assignment) and KEY (Event Trapping) Commands

8. unable to trap arrow key with key down event

9. Form_keydown event traps AltGR key instead of Alt-Key

10. Need to disable F1 key.

11. Showing custom Help by pressing the F1 key

12. Can't get the HelpProvider to work with the F1 key

 

 
Powered by phpBB® Forum Software