Archived

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

Reading strings from keyboard

This topic is 5900 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 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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites