Jump to content
  • Advertisement
Sign in to follow this  
dev578

Getting keyboard input

This topic is 4924 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 have a function that is called once per frame in DirectX. I need to be able to get a character array of all the characters the user typed on the keyboard. For example if the user hits the x key, then the y key, then the spacebar and the comma, I need a char array that contains "xy ,". Anyone know how I would go about doing this? Any help is appreciated, -Dev578 [Edited by - dev578 on April 25, 2005 3:04:33 PM]

Share this post


Link to post
Share on other sites
Advertisement
Put something into your windows message handler for WM_CHAR messages. MSDN can provide more, better details that I can.

Share this post


Link to post
Share on other sites
simple
//at start
std::string stuff = "";

//in framething
if(key_is_hit) stuff += "letter they hit";

Simplest way for custom ui in my opinion.

Share this post


Link to post
Share on other sites
DerAnged, thank you, that is a great idea. I just need to know what functions to use to be able to accomplish that. I am using C++ with Win32 API, and so far I see nothing that would allow me to do what you said above in pseudo. That is definately the right idea, I just want to have code run every frame that can update a buffer whenever neccessary. I don't want to use the MSGProc, because I am doing this whole GUI in a class, and I don't want to tie into the MSGProc, that would just make it harder on the user of the class. I was just looking at GetKeyboardState(), and it may be what I need, I just can't figure out how to use it the way I need to. If anyone could help, that would be great.

Any help is appreciated,



-Dev578

Share this post


Link to post
Share on other sites
GetKeyboardState is not very good for this kind of job. You won't know about order keys were pressed. I suggest using method DerAnged posted: in MsgProc react to WM_CHAR message (or if you want something more complex you could use WM_KEYDOWN and WM_KEYUP messages) and add characters to some buffer.
When I was working on my GUI I tried various methods and this is what I use now - it's not always perfect, but it works fine.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!