From: Nobody on
"k_zeon" <silvermaine2000(a)> wrote in message
> 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

That's because the hook code is called when the button is pressed and
depressed. On the first call, it unloads one form, then another form
actives, and when you release the button, the hook is called again. So you
need to ignore when the key is released. Also, in the hook you are not
checking to see if "code" parameter is less than 0(see that parameter
documentation), in which case you need to call CallNextHookEx() without
further processing. To check if the button is being pressed, use this code:

If (lParam And &H80000000) = 0 Then
' Key is down
End If