Skip to main content
GameDev.net gamedev.net
🔒 Locked

GetAsyncKeyState( )

Started by VoytekG Jun 15, 2002 at 3:14 PM 10 replies 1.2k views
Original Post
VoytekG
VoytekG
Hey! Can someone help me out with the GetAsyncKeyState() function? I know that you can use it for buttons like the escape buttom, which is VK_ESCAPE. That''s what I have in my program: if (GetAsyncKeyState(VK_ESCAPE)) { MessageBox(NULL, "Bye", "Exit", MB_OK); PostQuitMessage(0); } I was just wondering if it''s possible for me to use this function to get other keyboard buttons (is there a list, maybe?). I tried to use regular Ascii numbers. "d" is 100 for example, but when I put an if (GetAsyncKeyState(100)) it never returned true, always false. Does anyone know how I can make it recognize those keys? Or would I have to put it in the WndProc() function? Thanks, Voytek
http://www.liquidsoftware.cjb.netGames, apps, and more!
intransigent-seal
intransigent-seal
There should be a list of the "Virtual Key" constants (all beginning with VK_ like VK_ESCAPE) in help, or on MSDN.

As far as I know, they''re just scancode values (ie based on the position on the keyboard, not the position in the ASCII set).

Normal ones are VK_SPACE, VK_A to VK_Z etc.

John B
The best thing about the internet is the way people with no experience or qualifications can pretend to be completely superior to other people who have no experience or qualifications.
VoytekG
VoytekG
Hey!
When I put VK_A it gives me an error saying "Undeclared Identifier". I found a list on MSDN with the different VK_ values, but none of them deal with letters, only special keys on the keyboard.
Thanks,
Voytek
http://www.liquidsoftware.cjb.netGames, apps, and more!
Chem0sh
Chem0sh
For some strange reason, VK_A to VK_Z are not defined (neither are VK_0 to VK_9). You have to define them yourself. Search on MSDN for "virtual key codes". That will give you a list of all of the codes in hex. The simplist way to define them is to use an enumeration:


enum { VK_A = /*whatever the hex value is*/, VK_B, VK_C, //etc };


Anyone know why they aren''t already defined?

/*=========================================*/
/* Chem0sh */
/* Lead Software Engineer & Tech Support */
/* http://www.eFaces.biz */
/*=========================================*/
/*=========================================// Chem0sh// Lead Software Engineer & Tech Support// http://www.eFaces.biz=========================================*/
superpig
superpig
Aren''t they in some other, weird header file?

Superpig
- saving pigs from untimely fates
- sleeps in a ham-mock at www.thebinaryrefinery.cjb.net
Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse
Chem0sh
Chem0sh
I don''t know. I''ve never seen it. It would be nice if they were so I wouldn''t have to go around defining them all the time.

/*=========================================*/
/* Chem0sh */
/* Lead Software Engineer & Tech Support */
/* http://www.eFaces.biz */
/*=========================================*/
/*=========================================// Chem0sh// Lead Software Engineer & Tech Support// http://www.eFaces.biz=========================================*/
Thunder_Hawk
Thunder_Hawk
I read a post in one of the forums the other day that said that VK_A and such were only for Windows CE, anyways can''t you just go GetAsyncKeyState(''d'')? (that really aught to be the same as using 100...hmmm)

Hope that helps a bit

_____________________________

And the Phoenix shall rise from the ashes...

--Thunder_Hawk -- ¦þ
______________________________
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Forma
Chem0sh
Chem0sh
No, Thunder_Hawk, you can''t use ''d'' because virtual key codes are scan codes, not ascii codes. scan codes != ascii.

/*=========================================*/
/* Chem0sh */
/* Lead Software Engineer & Tech Support */
/* http://www.eFaces.biz */
/*=========================================*/
/*=========================================// Chem0sh// Lead Software Engineer & Tech Support// http://www.eFaces.biz=========================================*/
zealouselixir
zealouselixir
Actually, you can use ASCII codes with GetAsyncKeyState. However, they have to be the upper-case equivalents of the keys you want to check, e.g.

(GetAsyncKeyState(''A'') & 0x8000) ? true : false

will evaluate to true if the A key is pressed.

I personally define all the alphanumeric key constants in a header file.

Later,
ZE.


//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links
[twitter]warrenm[/twitter]
Chem0sh
Chem0sh


[edited by - Chem0sh on June 17, 2002 11:02:44 PM]
/*=========================================// Chem0sh// Lead Software Engineer & Tech Support// http://www.eFaces.biz=========================================*/
Promit
Promit
quote:
winuser.h
]/* VK_0 thru VK_9 are the same as ASCII ''0'' thru ''9'' (0x30 - 0x39) */
/* VK_A thru VK_Z are the same as ASCII ''A'' thru ''Z'' (0x41 - 0x5A) */

Would it really have killed you to read the header?


____________________________________________________________
Direct3D vs. OpenGL
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.