[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Virtual Key Code

Posted on 2003-11-13
11
Medium Priority
?
1,049 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
Technology Partners: 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 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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

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…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

656 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