Archived

This topic is now archived and is closed to further replies.

Keyboard Hook

This topic is 5126 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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~

Share this post


Link to post
Share on other sites