-
Wm_char
I am on the chapter "Keyboard" of petzold and I'm just a little foggy with the WM_CHAR message. I think that it is a different and separate message from WM_KEYDOWN, but then why does it send a WM_KEYDOWN message to the WndProc?
And, to get the char that the user pressed, you just do this:
Code:
/* CODE SNIPPET */
TCHAR newchar;
/*** SOME CODE DOWN ***/
switch (message)
{
case: WM_CHAR
{
newchar = (TCHAR) wParam;
}
/*** ETC... ***/
Do I pretty much have the right idea? I didn't write out the whole WndProc, but I wanted to make sure that I'm understanding:
>> newchar = (TCHAR) wParam;
Is this right? Thanks.
--Garfield
-
when a key is pressed your winproc recieves either a WM_KEYDOWN or a WM_SYSKEYDOWN. when the key is released the corresponding WM_KEYUP or WM_SYSKEYUP is sent. in these messages WPARAM contains the virtual keycode and LPARAM contains some other info such as repeat count and scan code and several flags. msdn will give more info.
now remember your messaging loop has this...
GetMessage(.....)
TranslateMessage(.....)
Ever wondered what TranslateMessage does?
This function actually translates the keystroke message into a character message and places the WM_CHAR into the message queue.
You can learn about the order the messages come in by running a program on the disc that comes with the book. Play around.Press some keys and see which messages are sent to your windproc.
-
Okay, I think I understand now. Say I press 'a', a WM_KEYDOWN and a WM_CHAR message will both be sent to my WndProc in that order, right? And then I can use a switch on the wParam to take the right actions for the char that was received for WM_CHAR. I understand, thanks!
--Garfield
-
Remember that a WM_CHAR message will be sent only for numbers and characters when WM_KEYDOWN will be sent for all characters and things like Crtl and the arrow keys.
-
acturaly you would get WM_SYSKEYDOWN . You only get WM_KEYDOWN for letters, numbers, punction(sp?), and other signs but not System keys like shift, Alt, Cntrl, and the other system keys.
-
You get WM_KEYDOWN messages for all keys except 'Alt'. Even 'Alt Gr'.