[C++] WM_CHAR and the delete key

Started by
3 comments, last by Anon Mike 13 years, 1 month ago
I need to capture data for a textbox object in my sprite engine, and so far I've been using WM_CHAR to get the characters I need. The problem is, WM_CHAR doesn't seem to generate a message when I press delete (or any other extended key) even though MSDN seems to imply that it does. Am I going to have to switch to WM_KEYDOWN?
It's a sofa! It's a camel! No! It's Super Llama!
Advertisement
You need to set a special style for the window for the extra characters to be sent. Something like "WANTSCHAR", don't remember the exact wording.
I think Vectorian aims at handling WM_GETDLGCODE and returning DLGC_WANTALLKEYS. I haven't tried but it might work.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Didn't seem to work, no WM_CHAR messages were generated when I pressed delete. I ended up just implementing WM_KEYDOWN above my WM_CHAR case and breaking if the LPARAM shows that the bit is not extended-- therefore, extended keys are sent to the same set of code, and non-extended keys are handled nicely and already translated for the keyboard by WM_CHAR. Works pretty well, though I had to add an additional wp+=1024 in the WM_KEYDOWN case so that my keycode processor could tell the difference between the delete key and the period key.
It's a sofa! It's a camel! No! It's Super Llama!
DELETE isn't a character, it's a key. Your solution of using WM_KEYDOWN is the right thing to do.

In general you need to use WM_CHAR for reading text and WM_KEY* for reading keys. For some reason a lot of people really want to use only one or the other. Resist that impulse, you inevitably run into problems like this.
-Mike

This topic is closed to new replies.

Advertisement