Im having problems with a dll im coding. For some reason the following code doesnt work correctly:
As you can see both of the IF statements use the system call to output a message to test.txt saying when the contents of the IF statements are being executed. This works correctly for setfocus but not keyskipped and i cant understand why because essentially they are the same code.
LRESULT CALLBACK HookProcedure (int nCode, WPARAM wParam, LPARAM lParam )
if (nCode == HCBT_KEYSKIPPED)
system("echo hcbt_keyskipped >> test.txt");
::PostMessage(mywindow, MSG_WM_KEYDOWN, wParam, lParam);
else if (nCode == HCBT_SETFOCUS)
system("echo hcbt_setfocus >> test.txt");
::PostMessage(mywindow, MSG_WM_SETFOCUS, wParam, lParam);
return CallNextHookEx( 0, nCode, wParam, lParam);
Note. This isnt a problem with the message MSG_WM_KEYDOWN or the mywindow variable. It also isnt a problem with my includes (i think!).
The way the setfocus works is when i run the dll whenever i change window it writes to the test.txt file showing it has registered the change of window focus, however when i press a key it should write to a the test.txt file showing it has registered the keypressing but it doesnt which implies IF(nCode == HCBT_KEYSKIPPED) is never true, but it should be. Im really stumped on this so any help would be appreciated.
This might be important. The above code works fine when ran on some computers but not others, which seems strange as they are all running winxp pro. This suggests that the coding is fine but the OS is set up differently on some computers allowing it to work but not on others... If anyone knows why this is so then please say. Thanks
HCBT_KEYSKIPPED (Third link down when google'ing "HCBT_KEYSKIPPED")
"Windows calls the WH_CBT hook with this hook code when a keyboard event is removed from the system queue and the keyboard hook is set. Windows will call a systemwide hook when a keyboard event is removed from any input queue and either a systemwide keyboard hook or a thread-specific hook for the current thread is installed. This hook code is not generated unless a filter function is attached to the WH_KEYBOARD hook. Despite its name, HCBT_KEYSKIPPED is called not only for skipped keyboard events but also whenever a keyboard event is removed from the system queue. Its main use is to install a WH_JOURNALPLAYBACK hook in response to a keyboard event. (See the "WM_QUEUESYNC" section below for more information.)"
Once upon a time, I wrote a hook doing what it appears you intend to accomplish, logging all keystrokes and the current application in which said keys are being stroked. I succeeded using two hooks: a WH_CBT for capturing various process information and WH_KEYBOARD for detecting key presses. Good luck.
thankyou for the information :-)
i must admit im a bit stumped from where to go from here. I guess i need to generate a filter funcation but i dont know what its purpose will be. I dont want you to supply the code as I want to code it myself and as I know my lecturer browses this board I may get into trouble for plagurism lol.
So if you can explain what the filter function will do and how to use it with the WH_KEYBOARD code then it would be very much appreciated.
Thanks a lot :-)
You probably replied before reading the edit appended to my previous message, but try using two hooks as I described. It should work well.
Keep us informed of your progress.