Solved

SetWindowsHookEx:  getting character codes rather than virtual key codes

Posted on 1997-08-12
2
866 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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Vb.Net Loading Word 11 103
Fix insertion and shifting issue 5 62
how to bring to back always mid parent image form 21 81
Windows Process running 3 54
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
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…

770 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