Reading strings from keyboard

Started by
3 comments, last by RelisH 22 years, 6 months ago
I did a search on this topic, and I found a ton of results, but I don''t understand any of them Does anyone know of a good and tutorial that will show you how to read in strings while using directx for entering names in top scores or something? Actually, showing me how to create a function that will return what key has just been pressed would suffice. Also, can someone point me to a good resource for these sorts of bits of info or how to properly search that mess Microsoft calls MSDN
-RelisH!
Advertisement
I use a simple BOOL array to store if a key is down or up(or mouse button, etc). It''s then easy to check if a key is down, and, using a function to set the up/down status, you can create a key press sort of idea. Then, in your window''s message procedure, just call the function on a WM_KEYDOWN or WM_KEYUP, etc.

As for strings, you can use a type-ahead buffer. When a key is pressed, and the user is in a textbox, or whatever, add that key to the end of the buffer. On a game update, just grab what''s in the buffer, add it to the string being modified, and reset the buffer to empty. This is a fairly elegant solution to the problem =).

Z.
______________"Evil is Loud"
Ah, sounds neat, but in the case of having very high framerates, wouldn''t some characters become repeated?
For example, if I were to tap the ''A'' key, but the program did two rendering passes while the key was pushed down. Does D3D input ignore keys that were held down like this?
-RelisH!
You should be able to change the amount of time between an update. So, when the user is in a typeing state, only update the game every 100ms. Or, if you have a function the set the state of a key, only push a character when the key is released:
  VOID KeyDown(char key){   keys[key] = FALSE;   if((bTyping) && (keyIsAlphaNumeric(key)))   {       type_ahead.push_back(key);   }   // ...}  

Something like the above should solve the problem by only pushing a character when the key is unpressed.

Z.
______________"Evil is Loud"
you should add the character to your buffer on key down (so it gets displayed at the right time), but don''t accept any other characters until you get a key up from that same key.


crazy166
some people think i''m crazy, some people know i am

This topic is closed to new replies.

Advertisement