Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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

My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!)

vbprogramming.8k.com

My Project (Need VB.NET Programmers)

http://workspaces.gotdotnet.com/ResolutionRPG

Posted

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;}

Posted
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.
Posted

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 ~ ^_^

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...