Link to home
Start Free TrialLog in
Avatar of Volga
Volga

asked on

Keyboard Hook

Please anybody can tell me (or better yet, show me where I can get a sample source code in Visual C++ V6) how to write a keyboard hook that intercepts keyboard data from all threads (global hook). I got the example from MSDN (Hooks32) but I could not compile in VC++ V6, apparently that was written under either VC++ V2 or V4.
Avatar of gelbert
gelbert

You can use SetWindowsHookEx with WH_KEYBOARD.
There is a sample by Paul DiLascia
in MSDN. Just look for "SetWindowsHookEx" keyword and scroll results until you see "C++ Q & A" for "Periodicals 1997". He is using this function in his program.
Also there are other samples for the same thing in MSDN
Another sample (if you do not have MSDN CD) is source code to "Visual C++ Windows Shell Programming" by Dino Esposito at www.wrox.com. Look around website for book page and there reference to download source code. Search source code for "SetWindowsHook"
ASKER CERTIFIED SOLUTION
Avatar of Wyn
Wyn

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Volga

ASKER

gelbert,
thanks for your suggestions but I had a hard time finding the right sample at the location.

wyn,
you are the closest who can give me some kind of sample code, even though I had to clean out some syntax error before being able to compile it. You have an extra ');' the line after SetWindowsHookEx.
I wrote an application that call SetTheHook in that dll but it looks like nothing happens. Do I need another hook (like WH_GETMESSAGE) to make it work?

Volga


Avatar of Volga

ASKER

wyn,

I have to accept your question, since I was able to compile the dll. But I'm still unable to write a program to translate the keyboard.