How "DirectInput" can detect two or more keys?

GoDarkCherries

Newcomer
Joined
May 31, 2004
Messages
16
I am implementing a simple 3D game that needs user interactions using the UP, DOWN, LEFT, RIGHT arrows to move an object on screen.
I successfully got each keys to work individually, but as soon as i press two or more keys at the same time, the program seems to be only picking up one key state.
If anybody got any suggesting or anything that might help me please post here. I am very much appreciated, thanks to all.

P.s I am using VC++ 6.0 Complier
 
hey,

here's how you would accomplish that:

(VB.NET code, sorry)

If KeyPressed(Keys.Left) Then

If KeyPressed(Keys.Space) Then

//do something when you pushed space and left at the same time

end if
end if

.. of course, you'd have to use your own function name, and your own way of checking individual key strokes

my point to you is,
DirectInput doesn't care about priority (whether you pushed left or space first doesnt matter),
as long as you check individual keys, and "check them together" like in an If statement, you should be able to check 2 or more at once
 
thanks

thank you for your reply, what you said is very true and right.
But i think i am expriencing another problem.
I did check the keys with the IF statements.
But only one key is being read at one time.
E.g. If i press UP KEY first, then LEFT KEY.. the LEFT KEY is ingored...

if(m_ProcessResult == UP)
{m_cameraPosZ += m_speed; m_cameraLookAtZ += m_speed;}

if(m_ProcessResult == LEFT) {m_cameraPosX -= m_speed; m_cameraLookAtX -= m_speed;}
 
Your code seems a bit strange. How can you store multiple keys in m_ProcessResult? You need a separate flag for each of the keys.
 
I know what i am gonna do now, since i am not using Joystick or other input devices, i have decided to use standard API function instead of DirectInput (Just for the sake of simplicity, it works).

"m_ProcessResult" is an integer which stores the return value from the keyboard state, i made a enum object of keys so i can refer to each individual keys using just one integer variable. (It might look a bit strange to VB programmer coz it is C stuff)

Thanks to those people who helped ~ ^_^
 
Back
Top