Solved

SetWindowsHookEx:  getting character codes rather than virtual key codes

Posted on 1997-08-12
2
859 Views
Last Modified: 2013-12-03
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
Comment
Question by:dmarteinson
2 Comments
 
LVL 7

Accepted Solution

by:
faster earned 100 total points
ID: 1403740
Why not use MapVirtualKey() to transalte the virtual key into character?

WH_KEYBOARD is correct.
0
 

Author Comment

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

0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now