Jump to content
  • Advertisement
Sign in to follow this  
chxfryer

Theres got to be a better way

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

There has to be a better way to do this, or more efficeint (spelling?) way. Right now, to get input for a chat program im writing, i check each and every key for a press through DirectInput; if a key is pressed, it returns the character for that key. ie. if (KeyDown(DIK_A)) return 'A'; if (KeyDown(DIK_B)) return 'B'; if (KeyDown(DIK_LSHIFT)) shift_down = true; if ((KeyDown(DIK_COMMA) && (shift_down)) return '<'; ... KeyDown is a is just a dummy function to return a keypress. is there someother way to quickly check the keys and return the character? Any thoughts/suggestions would be appreciated. Thanks

Share this post


Link to post
Share on other sites
Advertisement
For text input, Microsoft recommends using Windows messages (WM_CHAR/WM_KEYDOWN), instead of DirectInput. The WM_CHAR message covers all of the "regular" text keys. You would only need WM_KEYDOWN for cursor keys.

Share this post


Link to post
Share on other sites
If you really wanted to do something like that, you could set up a map of some sort, that mapped DIK constants to VK constants (VK is the set of constants used in the Windows API WM_KEYxxx messages and related places). It would tidier, I suppose.

But like Dave Hunt says, you'll make your life a lot easier if you use a regular message proc for this. The TranslateMessage part of the TranslateMessage/DispatchMessage loop will take care of all that shift logic for you, for example.

Share this post


Link to post
Share on other sites
Inside your WndProc function, you'd do something like this:

switch( msg )
{
case WM_KEYDOWN:
keyPressedID = wParam;
break;
}
// later use keyPressedID to find out which key was pressed

Share this post


Link to post
Share on other sites
Thanks for the input. Would the wm_char be decent for text input in a game? Basically, i am just making this chat program as a learning experience for a multiplayer game im wanting to develop.

Share this post


Link to post
Share on other sites
Yes, you can use WM_CHAR for text input in a game. You would not want to use it for keyboard game controls, but if you are doing things like getting the player's name, etc., then WM_CHAR is the way to go.

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!