Solved

Virtual Key Code

Posted on 2003-11-13
11
1,024 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

690 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