Sign in to follow this  
chxfryer

Theres got to be a better way

Recommended Posts

chxfryer    138
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
Dave Hunt    4872
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
dalep    331
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
chxfryer    138
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
Dave Hunt    4872
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this