Jump to content
  • Advertisement

Archived

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

StonerSunshine

Taking in Text Input

This topic is 5584 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 currently working on an OpenGL game project, and I need to be able to take in text input from the user. I tried using the _kbhit() function along with _getch() but they didn''t work at all. (The _kbhit() function never picked up when a key was hit. Maybe because I''m using Windows XP?) Does anyone know of a good way to take in text from the user other than an "if" check for every keyboard key? Thanks in advance for any help.

Share this post


Link to post
Share on other sites
Advertisement
The _kbhit and _getch functions are low level borland library functions that bypass the console to get input before the console does.

See, this is your problem; you have no console since you are running a windows application. Thus, you must use the Windows event handler to pick up keypresses. You must have an event handler, otherwise you won''t have a validly working windows application.

-----------------------------
Final Frontier Trader
If I were you, I would look into DirectInput. You can make a rather simple keyboard input routine for around, fifteen lines (give or take).
There are some good tutorials in the articles section, and the help files with DirectX SDK aren''t all that bad...

I don''t have a signature, sorry.

Share this post


Link to post
Share on other sites
Either that, or google for getAsyncKeyState(). This function allows you to query for any keypress.

Share this post


Link to post
Share on other sites
Thanks for the replies. I see... So, maybe I can use the Windows WM_KEYDOWN message to know when a key is hit. Is there a function that can tell me specifically which character was hit when the WM_KEYDOWN message is sent?

Share this post


Link to post
Share on other sites
I know about WM_CHAR, but aren''t Windows messages UINTs? I''m trying to get a "char" that I can append to the string that is being printed onscreen. Is there a call that can convert that UINT value into a char?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Handle WM_KEYDOWN, and the wParam (IIRC) parameter of your window proc contains the virtual key code for the key that was pressed.

Share this post


Link to post
Share on other sites

  • 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!