I try to understand windows hooks in .NET. I want to listen for pressed keys (global). I understand what the first and second parameters of SetWindowsHooks mean. The first parameter specifies the type of hook, e.g. 2 for WH_KEYBOARD and the second the callback handler, e.g. which function should be called if the event occurs.
And if I set the the last parameter to 0 I can intercept the events for all threads in the system.
But why (and how) I must specify the third parameter? I try to hook for WH_Keyboard (type 2) in my console application in this form:
hookID = SetWindowsHookEx((int) WH_TYPE.WH_KEYBOARD, hp,IntPtr.Zero, 0);
It doesn't work. Because IntPtr.Zero is not valid in this context. Can someone explain what the third parameter means and how I can specify a valid one so my console application can react to (global) WH_KEYBOARD events?
Thanks in advance