?
Solved

Virtual Key Code

Posted on 2003-11-13
11
Medium Priority
?
1,036 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
[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
  • 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 31

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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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
 
LVL 31

Accepted Solution

by:
Zoppo earned 150 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 31

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 31

Expert Comment

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

regards,

ZOPPO
0

Featured Post

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

762 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