virtual key codes

Started by
4 comments, last by deakin 23 years, 12 months ago
Windows for some reason has some problem with recognising virtual key codes for letters. It works fine when I use things like VK_RETURN, VK_ESCAPE, etc. but when I try to use something like VK_A it gives me an error. For example, the following code (using a GetAsyncKeyState macro): if (KEY_DOWN(VK_Y)){ return 1; } gets this error: error C2065: ''VK_Y'' : undeclared identifier Can anyone help me with this?? Thanks in advance. - Daniel
my homepage
- DanielMy homepage
Advertisement
VK_Y doesnt exist..

use WM_CHAR.

this is the key code after conversion with the TranslateMessage function.
WM_CHAR contains the TCHAR of the char key

If you can get your hands on an ascii code chart you can look up the ascii code for your key. e.g. the letter y is ascii 89. so you could write:

if(KEY_DOWN(89)) {
return 1;
}

-- Jon Hobson --
---------- JonHobson ----------

quote:Original post by JonHobson

If you can get your hands on an ascii code chart you can look up the ascii code for your key. e.g. the letter y is ascii 89. so you could write:

if(KEY_DOWN(89)) {
return 1;
}

-- Jon Hobson --

Actually you don''t need an ASCII-chart, this is easier:

if(KEY_DOWN(''y'')) {
return 1;
}
Gyzmo=============================="Well is the world standard" - The Alchemist"Not in Canada!" - jonnyfish
dont use WM_CHAR ,it will be slow
just use GetAsyncKeyState()
if(GetAsyncKeyState(VK_SPACE))
{
// your code
}

here''s the virtual key codes:VK_LBUTTON 01 Left mouse button
VK_RBUTTON 02 Right mouse button
VK_CANCEL 03 Control-break processing
VK_MBUTTON 04 Middle mouse button (three-button mouse)
— 05–07 Undefined
VK_BACK 08 backspace key
VK_TAB 09 tab key
— 0A–0B Undefined
VK_CLEAR 0C clear key
VK_RETURN 0D enter key
— 0E–0F Undefined
VK_SHIFT 10 shift key
VK_CONTROL 11 ctrl key
VK_MENU 12 alt key
VK_PAUSE 13 pause key
VK_CAPITAL 14 caps lock key
— 15–19 Reserved for Kanji systems
— 1A Undefined
VK_ESCAPE 1B esc key

well i dony have any time left to paste all the code

my web site

For some stupid reasons, the VK_A to VK_Z (and a few others) are commented out in the windows header file included with Visual C++, while the VK_RETURN are all left inside.

I think the rational is that VK_A to VK_Z are the same as ascii codes..

If u go to the definition of the VK_RETURN, you will see it there.

This topic is closed to new replies.

Advertisement