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.
C++, Win32 API - Virtual Key Codes??
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.
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.
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
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
#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 = 01HVK_RBUTTON = 02HVK_CANCEL = 03HVK_BACK = 08HVK_TAB = 09HVK_CLEAR = 0cHVK_RETURN = 0dHVK_SHIFT = 10HVK_CONTROL = 11H ; CTRL KEYVK_MENU = 12H ; ALT KEYVK_PAUSE = 13HVK_CAPITAL = 14HVK_ESCAPE = 1bHVK_SPACE = 20HVK_PRIOR = 21HVK_NEXT = 22HVK_END = 23HVK_HOME = 24HVK_LEFT = 25HVK_UP = 26HVK_RIGHT = 27HVK_DOWN = 28HVK_PRINT = 2aHVK_EXECUTE = 2bHVK_SNAPSHOT = 2ch ; Printscreen keyVK_INSERT = 2dHVK_DELETE = 2eHVK_HELP = 2fHVK_NUMPAD0 = 60HVK_NUMPAD1 = 61HVK_NUMPAD2 = 62HVK_NUMPAD3 = 63HVK_NUMPAD4 = 64HVK_NUMPAD5 = 65HVK_NUMPAD6 = 66HVK_NUMPAD7 = 67HVK_NUMPAD8 = 68HVK_NUMPAD9 = 69HVK_MULTIPLY = 6AHVK_ADD = 6BHVK_SEPARATER = 6CHVK_SUBTRACT = 6DHVK_DECIMAL = 6EHVK_DIVIDE = 6FHVK_F1 = 70HVK_F2 = 71HVK_F3 = 72HVK_F4 = 73HVK_F5 = 74HVK_F6 = 75HVK_F7 = 76HVK_F8 = 77HVK_F9 = 78HVK_F10 = 79HVK_F11 = 7aHVK_F12 = 7bHVK_F13 = 7cHVK_F14 = 7dHVK_F15 = 7eHVK_F16 = 7fHVK_F17 = 80HVK_F18 = 81HVK_F19 = 82HVK_F20 = 83HVK_F21 = 84HVK_F22 = 85HVK_F23 = 86HVK_F24 = 87HVK_NUMLOCK = 90HVK_SCROLL = 91H
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement