Jump to content
  • Advertisement
Sign in to follow this  
Raeldor

Gui Programming WM_KEYDOWN or WM_CHAR?

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

Hi All, I am starting on the GUI programming part of my game engine. It seems windows handles key press events two ways. WM_KEYDOWN gives keycodes, or you can translate the keycode (I am assuming based on your chosen keyboard layout) into character codes which gives a WM_CHAR message. I can see the WM_KEYDOWN being useful for the game controls, but sometimes I will want the user to key text into a dialog box. Should I use the WM_CHAR messages for this, or should I do the translation from WM_KEYDOWN into the character codes in my engine? I am guessing if I do this in my engine I will also have to track the status of the shift and caps locks keys also? How have others handled this? Thanks! Rael

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by garnet
I prefer WM_CHAR. It can hanle upper and lower cases, as well as UNICODE text, like Chinese.


Thanks. Maybe I'll try using both, similar to the way windows does. I can see the use of allowing the user to use the shift keys for controls too. I guess when dealing with a platform that has a keyboard as an input device you're always going to expect the operating system to be aware of the keyboard layout and regional settings so it's probably not 'cheating' to take advantage of the WM_CHAR message.

Share this post


Link to post
Share on other sites
Using the WM_CHAR also accounts for special characters (shift function for numbers and what not) and symbols, which are otherwise generally kind of a pain to deal with.

Share this post


Link to post
Share on other sites
You'll want to use WM_CHAR for any text input and WM_KEYDOWN for scrolling (in your textbox or something like a listbox), key combinations (like shortcuts), and game input.

Good luck!

Share this post


Link to post
Share on other sites
I use both, and have an input flag which changes the behavior of a ui object (take text, or not). The topmost object's params then determines which events are passed in and which are dropped. Er, I also use KEYUP, not down. Down will auto-repeat, Up will flag one per keystroke, and for that sort of event (usually) you only want to know if a keystroke occurs.

Share this post


Link to post
Share on other sites
Well the book I learnt from was OpenGL Game Programming, and that taught me to use DirectInput to handle keyboard input, instead of doing things the windows way. Anyone else have any views on this?

Share this post


Link to post
Share on other sites
Microsoft's ATG says "Don't use DirectInput for Mouse and Keyboard" :)

Taking advantage of High-Definition Mouse Movement

Quote:
DirectInput is a set of API calls that abstracts input devices on the system. Internally, DirectInput creates a second thread to read WM_INPUT data, and using the DirectInput APIs will add more overhead than simply reading WM_INPUT directly. DirectInput is only useful for reading data from DirectInput joysticks; however, if you only need to support the Xbox 360 controller for Windows, then use XInput instead. Overall, using DirectInput offers no advantages when reading data from mouse or keyboard devices, and the use of DirectInput in these scenarios is discouraged.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!