Solved

Virtual Key Code

Posted on 2003-11-13
11
1,010 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 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
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.

 

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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
sum28 challenge 31 115
EvenOdd challenge 10 126
wordappend challenge 8 200
Capture logon name 13 87
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: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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 video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

856 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