Better way to get input in games?

Started by
5 comments, last by someboddy 20 years, 3 months ago
I am using c\c++, and right now I''m gettin input like that:

while(kbhit())
 {
  k=getch();
  switch(k)
   {
    //all the input processing

    //based on the ''k'' I got on

    //this round of the loop.

   }
 }
I was using this method when I was programing in c. Is there a better way to do it on c++? ----------------------------------------- Everyboddy need someboddy!
-----------------------------------------Everyboddy need someboddy!
Advertisement
Depends what you''re using.

SDL and DirectX all have ways of getting input that are more suited to real-time games.
Or, if you want a quick and easy way, include windows.h and use SHORT GetAsyncKeyState(int vKey). I''d also recommend SDL or DirectX for more serious stuff though.
I am using turbo c++ 3 and I don''t have that inclue.

-----------------------------------------
Everyboddy need someboddy!
-----------------------------------------Everyboddy need someboddy!
You don''t have "windows.h"? Might I suggest upgrading your compiler? =)

If you want to get keyboard input the "Windows" way, your window procedure will probably look very similar to what you already have set up right now. However, if you''re aiming for a more.. platform-independent (straight C++) solution, I''m afraid I don''t know C++ console input well.
will directx solve the problem of not been able to input with two
keys at the same time

I''m doing my own version of rtype and i can''t move up and down and fire at the same time

any ideas?
quote:Original post by Anonymous Poster
will directx solve the problem of not been able to input with two
keys at the same time

I'm doing my own version of rtype and i can't move up and down and fire at the same time

any ideas?


Yes. DirectX will support as many simultaneous key presses as your hardware will allow. Typically it's 4 keys.

edit -- I believe SDL will allow this, as well.


[edited by - Dave Hunt on January 15, 2004 12:47:59 PM]

This topic is closed to new replies.

Advertisement