Solved

Virtual Key Code

Posted on 2003-11-13
11
998 Views
Last Modified: 2013-11-20
How can i get the virtual key code for a character?
their proberly is a simple function for this, but i don't seem to find it.
And i would also like to transfer into hex

thx in advance,
Maes
0
Comment
Question by:Maesy
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 9740542
The virtual key code for a character is its ASCII code - see the following taken from wínuser.h:

/* VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */
/* VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */
0
 
LVL 5

Expert Comment

by:waelothman
ID: 9744542
user the function
WM_KEYDOWN,or WM_KEYUP
the other function WM_KEYPRESS or WM_CHAR not valide with virtual key
0
 
LVL 30

Expert Comment

by:Zoppo
ID: 9745775
Hi Maesy,

there's a function VkKeyScan() which returns a value which low-byte is the virtual key code for all characters ...

hope that helps,

ZOPPO
0
 

Author Comment

by:Maesy
ID: 9759955
sorry for the late answer, but i was away for the weekend,
thx for the answers but i forgot to say that i'm working in embedded visual c and there that function doesn't seem to work.
you are right jkr that it is the ascii code, but i have one more question how can i transfer dec to hex?
0
 
LVL 5

Expert Comment

by:waelothman
ID: 9760071
you can do the function as

CString ToHex(int x)
{
    CString S;
   while (x)
   {
         int remain = x % 16 ;
         x = x /16;
        if (remain <10)
              S.Format("%d%s",,remain,S);
       else
              S.Format("%c%s",'A'+(remain-10,S);
    }
  if (S=="") S="0";
return S;
         

}
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 30

Accepted Solution

by:
Zoppo earned 50 total points
ID: 9762118
or simply:
CString ToHex( int x, int lenght = 4 )
{
 CString szHex;
 szHex.Format( "0x%x",x ); // creates a string like '0xff'
 return szHex;
}

if you want to have fixed length format you can  pass as format string i.e. "0x%08x" to generate strings like 0x000000ff ... use 'X' instead of 'x' to generate capital letters ...

ZOPPO
0
 
LVL 86

Expert Comment

by:jkr
ID: 9768505
So, I did NOT answer the Q "How can i get the virtual key code for a character?"? Surprising, I thought I read it like that...
0
 
LVL 30

Expert Comment

by:Zoppo
ID: 9769704
Hi jkr,

I agree ... therefor I added a Q to give you half of the points ... http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_20801273.html

See the good side: I promise to grade it with 'A' ...

Have a nice day,

regards,

ZOPPO
0
 

Author Comment

by:Maesy
ID: 9769977
excuse me
0
 
LVL 86

Expert Comment

by:jkr
ID: 9773917
Zoppo, I won't even comment there :o)
0
 
LVL 30

Expert Comment

by:Zoppo
ID: 9808911
hm, ok, jkr, it's your decision ...

regards,

ZOPPO
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Error on moodle after upgrade 3 106
conditional code and condition difference 9 65
fizzArray  challenge 1 47
wordcount challenge 11 76
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

757 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

13 Experts available now in Live!

Get 1:1 Help Now