Keyboard hook + C# problem
-
I have created a dll to hook onto all keyboard events (WH_KEYBOARD). The dll seems to work fine and captures messages indicating print screen has been pressed. I have checked that it works as intended by using a counter which counts each time the hookprocess gets called, and then printed the value to a file, which showed a correct value. My C# program in turn which of course is a windows application retrives the message correctly, but ONLY when the window has focus. If it's hidden (hide()) or just isn't in focus, it doesn't seem to process the message. The C# program starts by defining a custom window and from within it's constructor it installs the hook, and retrives a boolean indicating it's all fine. When the window is destroyed it's destructor uninstalls it. I use Windows XP pro SP1a. Any help appriciated
-
I have created a dll to hook onto all keyboard events (WH_KEYBOARD). The dll seems to work fine and captures messages indicating print screen has been pressed. I have checked that it works as intended by using a counter which counts each time the hookprocess gets called, and then printed the value to a file, which showed a correct value. My C# program in turn which of course is a windows application retrives the message correctly, but ONLY when the window has focus. If it's hidden (hide()) or just isn't in focus, it doesn't seem to process the message. The C# program starts by defining a custom window and from within it's constructor it installs the hook, and retrives a boolean indicating it's all fine. When the window is destroyed it's destructor uninstalls it. I use Windows XP pro SP1a. Any help appriciated
-
I have created a dll to hook onto all keyboard events (WH_KEYBOARD). The dll seems to work fine and captures messages indicating print screen has been pressed. I have checked that it works as intended by using a counter which counts each time the hookprocess gets called, and then printed the value to a file, which showed a correct value. My C# program in turn which of course is a windows application retrives the message correctly, but ONLY when the window has focus. If it's hidden (hide()) or just isn't in focus, it doesn't seem to process the message. The C# program starts by defining a custom window and from within it's constructor it installs the hook, and retrives a boolean indicating it's all fine. When the window is destroyed it's destructor uninstalls it. I use Windows XP pro SP1a. Any help appriciated
Further to this, have a look at: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/hooks/hookreference/hookfunctions/setwindowshookex.asp It may not be the thread thing i mentioned above, but rather the idHook parameter needs changed? Although could equally be the dwThreadId parameter. Let me know how it goes!!
-
Further to this, have a look at: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/hooks/hookreference/hookfunctions/setwindowshookex.asp It may not be the thread thing i mentioned above, but rather the idHook parameter needs changed? Although could equally be the dwThreadId parameter. Let me know how it goes!!
-
The message arrives so I don't think it has anything to do with the thread id. But I will take a closer look :).
I had a similair problem with windows hooks and it wasn't actually that the hook wasn't being fired, but in the callback function I was using readfile/writefile which apparently wasn't syncronizing right for multiple processes. So it was more of a process synchronization issue. I solved it using memory mapped files (which was more elegant anyway since it got rid of the need for a file at all for ipc).