how to generate VK_UP & VK_LEFT messages simultaneously?

Started by
3 comments, last by Buzz1982 20 years, 6 months ago
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
Advertisement
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
-----------------------"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
Try looking at it a different way - and instead of waiting for messages, query the keyboard state whenever you want. Use GetKeyboardState.
"Absorb what is useful, reject what is useless, and add what is specifically your own." - Lee Jun Fan
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
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!

This topic is closed to new replies.

Advertisement