Link to home
Start Free TrialLog in
Avatar of Maesy
Maesy

asked on

Virtual Key Code

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
Avatar of jkr
jkr
Flag of Germany image

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) */
Avatar of waelothman
waelothman

user the function
WM_KEYDOWN,or WM_KEYUP
the other function WM_KEYPRESS or WM_CHAR not valide with virtual key
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
Avatar of Maesy

ASKER

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

}
ASKER CERTIFIED SOLUTION
Avatar of Zoppo
Zoppo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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...
Hi jkr,

I agree ... therefor I added a Q to give you half of the points ... https://www.experts-exchange.com/questions/20801273/Points-for-jkr.html

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

Have a nice day,

regards,

ZOPPO
Avatar of Maesy

ASKER

excuse me
Zoppo, I won't even comment there :o)
hm, ok, jkr, it's your decision ...

regards,

ZOPPO