GoDarkCherries Posted May 31, 2004 Posted May 31, 2004 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 Quote
ThePentiumGuy Posted May 31, 2004 Posted May 31, 2004 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 Quote 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
GoDarkCherries Posted June 1, 2004 Author Posted June 1, 2004 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;} Quote
ThePentiumGuy Posted June 1, 2004 Posted June 1, 2004 sorry man i really dont know how to help you in this one Quote 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
Kavan Posted June 1, 2004 Posted June 1, 2004 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. Quote
GoDarkCherries Posted June 2, 2004 Author Posted June 2, 2004 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 ~ ^_^ Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.