Link to home
Start Free TrialLog in
Avatar of dmarteinson
dmarteinson

asked on

SetWindowsHookEx: getting character codes rather than virtual key codes

I am trying to capture the keystrokes passed to an application with SetWindowsHookEx.  I would like to record the actual characters that the user enters into the application (where possible), rather than virtual key codes.  From the helps, I expected to see WM_CHAR messages for each WM_KEYDOWN message.  Alternatively, a simple way to get the ASCII/unicode value corresponding to the virtual key code would do.

I install the handler from a .DLL that is started by the main application (the one that I am watching).  This works just fine.

SetWindowsHookEx( ..WH_KEYBOARD) gives me WM_KEYUP and WM_KEYDOWN as advertised, but I don't see any WM_CHAR messages.  

I have tried  WH_CALLWNDPROC and WH_CALLWNDPROCRET don't see keyboard messages and, as per the docs, these hooks slow the system down quite a bit.  I then tried WH_GETMESSAGE with the idea of issuing my own TranslateMessage() call to generate the WM_CHAR messages, but to no avail, since this handler doesn't see the WM_KEYDOWN messages either.
Finally, WH_JOURNALRECORD doesn't see WM_KEYUP/DOWN or WM_CHAR either.

Is there an easy way to capture these characters?  (I see a ToAscii() function but it wants several parameters, including a key-state array -- it seems to me that there has to be an easier way?)

Thanks in advance,
ASKER CERTIFIED SOLUTION
Avatar of faster
faster

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 dmarteinson
dmarteinson

ASKER

This gives me the unshifted character value -- I'd also like to distinguish lower from uppercase characters.