Win API - Virtual Keys

This topic is 3752 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I looked up the virtual keys and found that the keyboard number 1 is represented by a hexadecimal value of '30' in windows api. Using windows procedure how do I type this in?

Share on other sites
if ( GetAsyncKeyState(30) ){    foo();}

will do foo(); if 1 is pressed when the function is called

Share on other sites
Your question doesn't make much sense. I'm guessing you don't know how to use hex numbers in C/C++? Something like this:
if (vk == 0x31) whatever();    // 1 is hex 31, not 30

For the specific context of virtual keys it's probably clearer to this instead:
if (vk == '1') whatever();

For number and letter keys you can just use a character constant like that (use uppercase for letters, i.e. 'A'). For other keys you can use one of the standard VK_ constants. Some people also like to create VK_ constants for numbers and letters for consistency since the standard Windows headers don't do that themselves for some reason.

1. 1
2. 2
Rutin
20
3. 3
4. 4
frob
15
5. 5

• 9
• 9
• 13
• 9
• 33
• Forum Statistics

• Total Topics
632592
• Total Posts
3007284

×