🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

handling user input

Started by
4 comments, last by PsyOps 24 years, 6 months ago
What is the best way to handle user input: 1) via windows messages; 2) via direct input; or 3) other. Also, if you use direct input, does windows still generate keyboard and mouse messages. I look forward to your thoughts, please give me more than a simple 1, 2, 3.
Advertisement
It depends, if your game is fullscreen or not. For windowed mode, I would use DirectInput in non-exclusive mode (so that Windows and other apps can use the mouse and keyboard while you''re using them). For fullscreen, I would use the exclusive mode which totally shuts out Windows. After all, what else needs input when your game is taking over the entire screen?

Oh, and Windows doesn't generate input messages when you set exclusive mode. At least I don't think so.

Edited by - foofightr on 1/2/00 6:49:39 PM
Nope, if you set exclusive mode, windows doesn''t post messages.. Helps performance slightly I guess :)
How would I get a string from the user? Like, if I want to get the user''s name.

- mallen22@concentric.net
- http://members.tripod.com/mxf_entertainment/
Hmmm....

Interesting proposal. Although I used direct input for controlling the player''s direction I never had someone enter text through keyboard and display it while in direct input mode. Why not just check the key that was struct in immediate mode, by checking the array of 256 keys. If key was hit then determine which key was hit by doing an if() comparison and based on that save the letter into a string array. This array should be singular and shared among the different if() comparison functions. I can see one problem with this though. While you hit a key and hold it down even for a 1/20th of a second, the computer is so fast as to produce many key hits during this time period and each one is cought and deposited into the array of chars. So you end up with 20 letter ''L'', then 30 letter ''O'', etc. You could put Sleep() right after you check for individual keys to slow down the code, or somehow based on time elapsed between first check and last check you determine to not call the comparison function for some time. That way the code''s speed will be machine independent. I manually slowed down my esc key to 200ms but on faster machines that value should be incremented. I think for the situation where you need so save chars the way to go is with regular TranslateMessage() code in you message loop and have the message sent into you window procedure function and act on the letter when processing the WM_CHAR message. Or present the user with a table of letters to choose from by clicking on them with a mouse instead of the keyboard or navigate the table with the cursor keys and use highlighting of the selected letter. Then when user presses the return key store the letter. Try to search this forum which might bring something more fruitful then my explanation.
typing in something in graphics mode doesn't have to be any different than in console mode. you used to use getch() for that before, but now you can't, so why not simulate it? here's something crude:
void KB_Getch (){  static double lastFrame = -1.0;  // rev limiter :)  // (0.5 seconds is a good value for repeatDelay)  while (get_time() < lastFrame + repeatDelay)    ;  // returns the first key found, and unless the user is  // slamming his fist down at the keyboard, this will be  // accurate one key at a time  while (1)  {    key->GetDeviceState(key_table...);    for (i=0 ; i<256 ; i++)      if (key_table) // it thinks im trying to do italics!<br>        return (i);<br>  }<br>}<br>  </pre>  <br>note that I never used this, I just conjured it up right now.<br><br>Edited by - foofightr on 1/4/00 3:38:09 AM    

This topic is closed to new replies.

Advertisement