|
-
Sep 25th, 2002, 07:19 AM
#1
Thread Starter
Frenzied Member
Virtual Keys
I'm trying to trap the 'W' key with the following code, but it doesn't work:
Code:
if (KEY_DOWN(VK_W))
// Move player two up
Code:
if (KEY_DOWN(57))
// Move player two up
Neither works...
-
Sep 25th, 2002, 07:51 AM
#2
PowerPoster
Try using GetAsyncKeyState instead of KEY_DOWN.
-
Sep 25th, 2002, 03:54 PM
#3
Fanatic Member
What is KEY_DOWN?? Where did u get that? Is it a MACRO of some sort? Try what abdul said or just do a
#define KEY_DOWN(x) GetAsyncKeyState(x)
-
Sep 25th, 2002, 04:49 PM
#4
Frenzied Member
I've had troubles with it
-
Sep 25th, 2002, 07:14 PM
#5
PowerPoster
GetAsyncKeyState will return 0 if it fails so you should check it like this....
PHP Code:
if(GeAsyncKeyState(0x57) != 0)
{
//Key was pressed
}
Remember the code for the "W" key is in hexadecimal (0x57), not just 57.
-
Sep 26th, 2002, 12:00 PM
#6
Thread Starter
Frenzied Member
oohhh! now I get it! thx!
-
Sep 27th, 2002, 05:28 AM
#7
The return value of GetAsyncKeyState should only be tested for the highest bit set:
Code:
inline bool KEY_DOWN(int vk) {
return (GetAsyncKeyState(vk) & 0x80) != 0;
}
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|