Archived

This topic is now archived and is closed to further replies.

getting user input in C++

This topic is 5173 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m interested to know how most modern games get user input (as in keypresses, not inputted numbers and stuff). I can think of three ways of doing it: 1: using the console; getting console input with something like . The drawback is that, well, you can only make console based games. 2: writing the game as a windows app (or similar. uh... I assume there''s something similar on other platforms) and the message loop. *shudder*. The drawbacks are that it''s not portable and that you have to mess around with all that windows crap. 3: somehow writing your own input drivers in assembly? Are there other ways of doing it, preferably which don''t have any of these drawbacks? Is it always implementation specific? Do windows programs HAVE to use that silly message passing stuff to get input?

Share this post


Link to post
Share on other sites
SDL is quite easy to use for input handling. It still uses message queues, but they are simpler than the Windows ones. SDL also works on most non windows platforms.

Share this post


Link to post
Share on other sites
Or you can be really cheap and get a character from the keyboard and cast it as an int and use if''s to do actions based on what key he presses.

example:

char ckey,
int ikey;

ckey = getch();
ikey = (int)ckey;
if(ikey == 27) //Exit button integer wise on the keyboard
{
return 0;
}



Share this post


Link to post
Share on other sites
there is a standard windows call that is OK for small scale demos, called GetAsyncKeyState(), and one that gets the whole keyboard map.

DirectInput is what games use for inputs. It''s fast and easy. And Joysticks and mouse supports is then a few lines of code away

Share this post


Link to post
Share on other sites
quote:
Original post by oliii
DirectInput is what games use for inputs. It''s fast and easy. And Joysticks and mouse supports is then a few lines of code away



DirectInput easy? Maybe, but a heck of a lot more setup code than using the message loop. Besides, a well-designed system will take advantage of both. Use the version of DirectInput you want if it''s available, fall back to the message loop if not.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
im havin troubles ... does any one know how to get user input such as numbers to use in formulas for a math based game ????

Share this post


Link to post
Share on other sites