From: k_zeon on
Hi

I have a Form and on the form a WebBrowser Control
I use this to display info.

I have other forms and set the KeyPreview of the form to True and have a
keypress event set so that if i press the escape key the form unloads

But the form I have the Webbrowser control on does not trap the event and
will not close

is there another way to trap this event ie API or such

any help is appreciated

many thanks

Garry



From: Nobody on
"k_zeon" <silvermaine2000(a)googlemail.com> wrote in message
news:O4ODkwBgKHA.4528(a)TK2MSFTNGP06.phx.gbl...
> Hi
>
> I have a Form and on the form a WebBrowser Control
> I use this to display info.
>
> I have other forms and set the KeyPreview of the form to True and have a
> keypress event set so that if i press the escape key the form unloads
>
> But the form I have the Webbrowser control on does not trap the event and
> will not close
>
> is there another way to trap this event ie API or such
>
> any help is appreciated

Use SetWindowsHookEx(WH_KEYBOARD). Search the web for samples. Another way,
but less elegant is to call GetAsyncKeyState(vbKeyEscape) in a Timer, but
you may not be able to see that the key was pressed if you are not calling
it fast enough.


From: k_zeon on
Hi

I found some examples of SetWindowsHookEx(WH_KEYBOARD). but cannot get it to
work properly
If I have one form then all works ok.
What I would like to do is set it up so it allows me to work with multiple
forms

ie each form that loads I can hit the escape button and the form unloads.

at the moment i have tweaked some simple code but it always unloads all my
forms

Here is my Module code::
Private Declare Function SetWindowsHookEx Lib "user32" Alias
"SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As
Long, ByVal dwThreadId As Long) As Long
Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As
Long) As Long
Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long,
ByVal ncode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const WH_KEYBOARD = 2

Private mlngHookId As Long
Private MyFormtoUnload As Form

Public Sub SetFormName(ByVal Formname As Form)
Set MyFormtoUnload = Formname
End Sub

Public Sub StartKeyHook()
mlngHookId = SetWindowsHookEx(WH_KEYBOARD, AddressOf KeyProc, App.hInstance,
App.ThreadID)
End Sub

Public Sub StopKeyHook()
UnhookWindowsHookEx mlngHookId
End Sub

Private Function KeyProc(ByVal ncode As Long, ByVal wParam As Long, ByVal
lParam As Long) As Long
On Error GoTo err
If wParam = 27 Then
Unload MyFormtoUnload

End If
KeyProc = CallNextHookEx(mlngHookId, ncode, wParam, lParam)
err:
End Function


And here is the form code::

Private Sub Form_Activate()
SetFormName Me
End Sub

Private Sub Form_Load()
StartKeyHook
End Sub

Private Sub Form_Unload(Cancel As Integer)
StopKeyHook
End Sub

hope someone can help

thanks


Garry

"Nobody" <nobody(a)nobody.com> wrote in message
news:ObZWq3BgKHA.5564(a)TK2MSFTNGP06.phx.gbl...
> "k_zeon" <silvermaine2000(a)googlemail.com> wrote in message
> news:O4ODkwBgKHA.4528(a)TK2MSFTNGP06.phx.gbl...
>> Hi
>>
>> I have a Form and on the form a WebBrowser Control
>> I use this to display info.
>>
>> I have other forms and set the KeyPreview of the form to True and have a
>> keypress event set so that if i press the escape key the form unloads
>>
>> But the form I have the Webbrowser control on does not trap the event and
>> will not close
>>
>> is there another way to trap this event ie API or such
>>
>> any help is appreciated
>
> Use SetWindowsHookEx(WH_KEYBOARD). Search the web for samples. Another
> way, but less elegant is to call GetAsyncKeyState(vbKeyEscape) in a Timer,
> but you may not be able to see that the key was pressed if you are not
> calling it fast enough.
>
>
From: Henning on

"k_zeon" <silvermaine2000(a)googlemail.com> skrev i meddelandet
news:O4ODkwBgKHA.4528(a)TK2MSFTNGP06.phx.gbl...
> Hi
>
> I have a Form and on the form a WebBrowser Control
> I use this to display info.
>
> I have other forms and set the KeyPreview of the form to True and have a
> keypress event set so that if i press the escape key the form unloads
>
> But the form I have the Webbrowser control on does not trap the event and
> will not close
>
> is there another way to trap this event ie API or such
>
> any help is appreciated
>
> many thanks
>
> Garry
>

Does it work if you add an Exit button and set its Cancel property to True.
In its Click Event use Unload Me to Close the Form.

/Henning


From: k_zeon on
excellent. so simple but effective

many thanks

Garry

"Henning" <computer_hero(a)coldmail.com> wrote in message
news:OPpvylCgKHA.2160(a)TK2MSFTNGP02.phx.gbl...
>
> "k_zeon" <silvermaine2000(a)googlemail.com> skrev i meddelandet
> news:O4ODkwBgKHA.4528(a)TK2MSFTNGP06.phx.gbl...
>> Hi
>>
>> I have a Form and on the form a WebBrowser Control
>> I use this to display info.
>>
>> I have other forms and set the KeyPreview of the form to True and have a
>> keypress event set so that if i press the escape key the form unloads
>>
>> But the form I have the Webbrowser control on does not trap the event and
>> will not close
>>
>> is there another way to trap this event ie API or such
>>
>> any help is appreciated
>>
>> many thanks
>>
>> Garry
>>
>
> Does it work if you add an Exit button and set its Cancel property to
> True. In its Click Event use Unload Me to Close the Form.
>
> /Henning
>
>