Archived

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

how to generate VK_UP & VK_LEFT messages simultaneously?

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

hi, i m making a demo in which camera is moving through a world. but i m unable to move the camera in direction generated by pressing two keys simultaneously(and continously)say up arrow key & left arrow key.the camera is moving in either up direction or in left direction.i think the virtual key messages VK_UP & VK_DOWN are not generating simultaneously. is there any way of doing thing like this in win32?so that both messages be generated simultaneously or in alternate if not simultaneously by continously pressing these keys.so that the camera can move in 45 degree direction. thanx

Share this post


Link to post
Share on other sites
Instead of checking if the key is pressed with windows each frame, store it in your program when a key is pressed down and when a key is let go, and work with that... ie:

if both keys are pressed, move at a 45 degree angle, else move either straight foward or to the side..

or you could even do one after another.. check up key and move forward, then check left key and move left, tho moving diagonally will then move faster than if running straight forward.

-----------------------
"When I have a problem on an Nvidia, I assume that it is my fault. With anyone else''s drivers, I assume it is their fault" - John Carmack

Share this post


Link to post
Share on other sites
hi
thanx, the problem is solved. i have used GetKeyState() function to query the state of the keys. however i didn''t understand the difference b/w GetKeyState() & GetAsyncKeyState().
both seems to do the same work.

bye

Share this post


Link to post
Share on other sites
The ''GetAsyncKeyState'' function is an interrupt level access to keyboard/mouse

2 quick macros:

// Test if a key is down
#define KEYDOWN(vk_key) (GetAsyncKeyState(vk_key) & 0x8000)

// Test if a key went down since last call to ''GetAsyncKeyState''
// kinda a single press whereas #KEYDOWN is like auto-fire
#define KEYPRESS(vk_key) (GetAsyncKeyState(vk_key) & 0x0001)

Hope that helps!

Share this post


Link to post
Share on other sites