• Advertisement
Sign in to follow this  

C++, Win32 API - Virtual Key Codes??

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to get my win32 program to recognize whenever the 'M' key is pressed. I tried 'VK_M' however, I get a compiler error. At the moment I can only get the escape key working.
Quote:
case WM_KEYDOWN: int fwKeys; LPARAM keyData; fwKeys = (int)wParam; // virtual-key code keyData = lParam; // key data switch(fwKeys) { case VK_ESCAPE: PostQuitMessage(0); break; default: break; } break; default:
Does anyone know how I could get the 'M' key code in a case statement in this code? I checked http://msdn2.microsoft.com/en-us/library/ms927178.aspx however, that page doesn't contain the information I need.

Share this post


Link to post
Share on other sites
Advertisement
Try handling the WM_CHAR message, with something like case 'M', or similar, you may have to check wParam and lParam to handle the case sensitivity.

Share this post


Link to post
Share on other sites
that page you referenced is for Windows CE. the win api one is more complete. just filter "Virtual-Key Codes" search in offline MSDN using C++ language filter to get to the win32 version of that page.

M would be 0x4D


(30)
0 key

(31)
1 key

(32)
2 key

(33)
3 key

(34)
4 key

(35)
5 key

(36)
6 key

(37)
7 key

(38)
8 key

(39)
9 key

- (3A-40)
Undefined

(41)
A key

(42)
B key

(43)
C key

(44)
D key

(45)
E key

(46)
F key

(47)
G key

(48)
H key

(49)
I key

(4A)
J key

(4B)
K key

(4C)
L key

(4D)
M key

(4E)
N key

(4F)
O key

(50)
P key

(51)
Q key

(52)
R key

(53)
S key

(54)
T key

(55)
U key

(56)
V key

(57)
W key

(58)
X key

(59)
Y key

(5A)
Z key

Share this post


Link to post
Share on other sites

#define VK_0 0x30
#define VK_1 0x31
#define VK_2 0x32
#define VK_3 0x33
#define VK_4 0x34
#define VK_5 0x35
#define VK_6 0x36
#define VK_7 0x37
#define VK_8 0x38
#define VK_9 0x39
///////
#define VK_A 0x041
#define VK_B 0x042
#define VK_C 0x043
#define VK_D 0x044
#define VK_E 0x045
#define VK_F 0x046
#define VK_G 0x047
#define VK_H 0x048
#define VK_I 0x049
#define VK_J 0x04A
#define VK_K 0x04B
#define VK_L 0x04C
#define VK_M 0x04D
#define VK_N 0x04E
#define VK_O 0x04F
#define VK_P 0x050
#define VK_Q 0x051
#define VK_R 0x052
#define VK_S 0x053
#define VK_T 0x054
#define VK_U 0x055
#define VK_V 0x056
#define VK_W 0x057
#define VK_X 0x058
#define VK_Y 0x059
#define VK_Z 0x05A


Some other keys for reference:


VK_LBUTTON = 01H
VK_RBUTTON = 02H
VK_CANCEL = 03H
VK_BACK = 08H
VK_TAB = 09H
VK_CLEAR = 0cH
VK_RETURN = 0dH
VK_SHIFT = 10H
VK_CONTROL = 11H ; CTRL KEY
VK_MENU = 12H ; ALT KEY
VK_PAUSE = 13H
VK_CAPITAL = 14H
VK_ESCAPE = 1bH
VK_SPACE = 20H

VK_PRIOR = 21H
VK_NEXT = 22H
VK_END = 23H
VK_HOME = 24H
VK_LEFT = 25H
VK_UP = 26H
VK_RIGHT = 27H
VK_DOWN = 28H

VK_PRINT = 2aH
VK_EXECUTE = 2bH
VK_SNAPSHOT = 2ch ; Printscreen key
VK_INSERT = 2dH
VK_DELETE = 2eH
VK_HELP = 2fH

VK_NUMPAD0 = 60H
VK_NUMPAD1 = 61H
VK_NUMPAD2 = 62H
VK_NUMPAD3 = 63H
VK_NUMPAD4 = 64H
VK_NUMPAD5 = 65H
VK_NUMPAD6 = 66H
VK_NUMPAD7 = 67H
VK_NUMPAD8 = 68H
VK_NUMPAD9 = 69H
VK_MULTIPLY = 6AH
VK_ADD = 6BH
VK_SEPARATER = 6CH
VK_SUBTRACT = 6DH
VK_DECIMAL = 6EH
VK_DIVIDE = 6FH

VK_F1 = 70H
VK_F2 = 71H
VK_F3 = 72H
VK_F4 = 73H
VK_F5 = 74H
VK_F6 = 75H
VK_F7 = 76H
VK_F8 = 77H
VK_F9 = 78H
VK_F10 = 79H
VK_F11 = 7aH
VK_F12 = 7bH
VK_F13 = 7cH
VK_F14 = 7dH
VK_F15 = 7eH
VK_F16 = 7fH
VK_F17 = 80H
VK_F18 = 81H
VK_F19 = 82H
VK_F20 = 83H
VK_F21 = 84H
VK_F22 = 85H
VK_F23 = 86H
VK_F24 = 87H

VK_NUMLOCK = 90H
VK_SCROLL = 91H

Share this post


Link to post
Share on other sites
Quote:
Original post by TheUmpteenth
you can just use GetKeyState('M');
or case 'M'

needs to be upper case


ah! you're right! ha ha ha. just use 'M'. after all these years of windows programming i've never paid attention to those hex values listed in MSDN... to realize they are the same as the ascii values for 0-9 and A-Z! just goes to show what goes through my head every time i see hex lol

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement