I have written the following method that prevents all keys from being pressed:
private IntPtr HookHandler(int nCode, IntPtr wParam, ref KBDLLHOOKSTRUCT lParam)
{
if (nCode >= 0)
{
...
//Return a nonzero value to prevent the system from passing the message to the
//rest of the hook chain or the target window procedure.
return (IntPtr)1;
}
return NativeMethods.CallNextHookEx(_hookID, nCode, wParam, ref lParam);
}
When the above code runs, though, it allows keys like my keyboard's calc key or the email key, etc.
I debug, and the code does get to the return (IntPtr)1;
line (and it does show correctly what key is being pressed), but by then, the calc window (or other) has already opened. Even if I return a 1, its too late.
Is there something I can be doing different here?