Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

deakin

virtual key codes

This topic is 6933 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

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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 --

Share this post


Link to post
Share on other sites
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;
}

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!