Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SetWindowsHookEx:  getting character codes rather than virtual key codes

Posted on 1997-08-12
2
Medium Priority
?
913 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 7

Accepted Solution

by:
faster earned 200 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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

618 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