[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 926
  • Last Modified:

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,
0
dmarteinson
Asked:
dmarteinson
1 Solution
 
fasterCommented:
Why not use MapVirtualKey() to transalte the virtual key into character?

WH_KEYBOARD is correct.
0
 
dmarteinsonAuthor Commented:
This gives me the unshifted character value -- I'd also like to distinguish lower from uppercase characters.

0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now