Theres got to be a better way

Started by
4 comments, last by Dave Hunt 18 years, 6 months ago
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
::fart::
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.
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.
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
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.
::fart::
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.

This topic is closed to new replies.

Advertisement