[C++] WM_CHAR and the delete key
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?
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.
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.
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement