Keyboard Hook

Started by
3 comments, last by Zern 20 years, 4 months ago
Hello, I created a dynamic link library which is loaded up from Application_A which has a KeyboardProc handler, and inside Application_A I call an exported function from the dynamic link library to initialize SetWindowsHookEx(WH_KEYBOARD..etc) now the thing is inside the .DLL, the keyboard hook gets called ONLY when I do not use any Send/Post Message functions to notify Application_A of keyboard events. Also, yes I use a function to set the server handle, which does in fact work, I used GetWindowText to see if it was valid/etc and it does work. Now, Send/Post message in the .dll *DOES* work when Application_A has focus, but when Application_B has focus, and the DLL has Post/Send message, it doesn't work. Any ideas? This problem has been boggling me for several weeks now and I cannot find a solution. Thanks in advance. EDIT: Figured I will explain what this is for before immature children assume it is for illegal activities. What I'm attempting to do is copy mouse(will get to work after keyboard) events and keyboard events and save them to replay so I can automate things in a computer game. [edited by - zern on November 30, 2003 5:07:42 PM]
Advertisement
I take it you''re trying to hook "Process B"? Are you using WM_COPYDATA to pass the information from Process B back to Process A? If not, what mechanism are you using?
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
LessBread,

That is correct, I am attempting to hook "ProcessB" then pass information back. No, I am not using WM_COPYDATA. What I am doing is using RegisterWindowsMessage("KEYBRD_HOOK_EVENT"), creating the message in the application that loads the .dll. Inside the dll, I also create a static variable that gets the ID value of the message. Then the KeyboardProc that handles the key events, is calling PostMessage(ServerHandle, idKeybrdHookEvent, 0, 0); (yes, wparam, lparam are 0 for testing purposes now - I want to recieve the message in the Server first before I start to process actual data).

Then, inside the WinProc I have a switch of keybrd_hook_event message and a message box that pops if a message comes through, which does not happen.



Thanks in advance.

NOTE: ServerHandle is the handle of the application that loads the actual .dll. Code of the custom windows message handler is inside the server application, and is similiar to the following:

if(message == idKeybrdHookEvent)
{
MessageBox(hwnd, "Works", "idKeybrdHookEvent", MB_OK);
return 0;
}

[edited by - zern on December 1, 2003 11:30:33 AM]
I''m kinda rushed at the moment, so I can''t address your immediate problem. However, there''s a sample keyboard hook that works here: Systemwide Windows Hooks without external DLL. The author makes a big deal out of using an exe to accomplish the hook, but his text gets a few things wrong, namely that his sample code only works with the low level hooks, WH_MOUSE_LL && WH_KEYBOARD_LL, and that means it only works on W2K or better. That might not resolve your problem in a satisfactor manner, but perhaps it will shed some light on it just the same.
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
Thank you for the link. I will attempt to simulate it tonight when I have some free time. Hopefully I can get WH_KEYBOARD to work instead of WH_KEYBOARD_LL as I do assume some users of my program will run it on windows98/me/etc and not NT+.


Thanks again for the link,
Zern~

This topic is closed to new replies.

Advertisement