Learn how to a build a cloud-first strategyRegister Now


C++ get virtual key-code from LPSTR

Posted on 2009-04-28
Medium Priority
Last Modified: 2012-05-06
I have some code below to try and extract a virtual key-code from a Edit control...  It's not working out at all...

I need to save it to the Registry, and then load it back in =(

For instance, if I put 'Q' in the textbox, I get 337 as the number (WRONG WRONG WRONG =()


						LPSTR sHotKey;
						GetWindowText(GetDlgItem(hwnd, IDC_HOTKEY), sHotKey, 2);
						short iHotKey=VkKeyScan(*sHotKey);
						RegWrite(regkey, "Hotkey", iHotKey);
//Nothing so far, as I can't even extract it properly, but I would need to SetWindowText...

Open in new window

Question by:jake072
  • 4

Accepted Solution

tulasisiva earned 2000 total points
ID: 24250887
int GetKeyNameText( LONG lParam,   LPTSTR lpString,    int nSize );
UINT MapVirtualKeyEx(          UINT uCode,    UINT uMapType,    HKL dwhkl);

try to use this two methods for your requirement.
Check MSDN for indetailed details.
LVL 14

Author Comment

ID: 24280783

I am aware of the functions, however, I cannot figure out how to make them work.

I have a Edit control, IDC_HOTKEY, which is set to receive 1 upper-case character to interpret.  I need to store the scan code in the registry and then load the scan code from the registry to populate the edit control on load.

I have been working with this for a week now, and cannot figure it out.  Could you help me?

LVL 14

Author Comment

ID: 24314240
No one can give me an example of how to do this?  PLEASE!!

LVL 14

Author Comment

ID: 24338840

I finally figured out what I was doing wrong... I was extracting the LOBYTE of the returned short from VkKeyScan =)

Attached code...  iHotKey will store the VK code; thanks, should've read more =)

int iHotKey;
short vHotKey;
vHotKey = VkKeyScan(*sHotKey);
iHotKey = LOBYTE(vHotKey);

Open in new window

LVL 14

Author Closing Comment

ID: 31575456
Thanks again, included below is the code implementation; don't forget to use LOBYTE like I did =) !!!

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month20 days, 18 hours left to enroll

810 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