WM_CHAR
- From: "Norman Diamond" <ndiamond@xxxxxxxxxxxxxxxx>
- Date: Wed, 1 Mar 2006 19:14:58 +0900
From reading MSDN it seems possible for a program to process WM_CHARmessages instead of WM_KEYDOWN and WM_KEYUP. Some details are pretty hard
to understand though.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/keyboardinput/aboutkeyboardinput.asp?frame=true
An application that processes keyboard input typically ignores all but the
WM_CHAR and WM_UNICHAR messages, passing any other messages to the
DefWindowProc function. Note that WM_CHAR uses 16-bit Unicode
Transformation Format (UTF) while WM_UNICHAR uses UTF-32.
OK, that sounds fine so far.
The wParam parameter of all character messages contains the character code
of the character key that was pressed. The value of the character code
depends on the window class of the window receiving the message. If the
Unicode version of the RegisterClass function was used to register the
window class, the system provides Unicode characters to all windows of
that class. Otherwise, the system provides ASCII character codes.
For a moment that sounds fine by itself, for one particular country's
version of Windows. But these two paragraphs contradict each other. The
first says that WM_CHAR uses UTF-16 without exception. The second says that
WM_CHAR chooses between UTF-16 and ASCII depending on whether the window
class was registered using RegisterClassW or RegisterClassA. For a moment
it still looks OK for one country's version because ASCII codepoints
magically map onto equal UTF-16 codepoints.
But the same page admits to the existence of French, German, etc. If a
keyboard has even one non-ASCII character that can be input directly without
the use of dead keys, then which paragraph is true? WM_CHAR always uses
UTF-16? Or WM_CHAR chooses between UTF-16 and the user's code page
depending on which kind of RegisterClass function was called?
Further reading yields problems with the second paragraph all by itself.
And with the first paragraph all by itself. What is the ASCII code of an
up-arrow? What is UTF-16 of an up-arrow?
And what about some of the other non-system keys, keys which can be pressed
without holding down the Alt key. Read on...
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/keyboardinput/keyboardinputreference/keyboardinputmessages/wm_char.asp
The WM_CHAR message uses Unicode Transformation Format (UTF)-16.[...]
Minimum operating systems Windows 95, Windows NT 3.1
OK, even since Windows 95, WM_CHAR used UTF-16 with no exceptions, no ASCII.
Let's ignore the contradiction with the other page. Um, let's forget about
Windows 95 too, sorry for this interruption.
For enhanced 101- and 102-key keyboards, extended keys are the right ALT
and the right CTRL keys on the main section of the keyboard; the INS, DEL,
HOME, END, PAGE UP, PAGE DOWN and arrow keys in the clusters to the left
of the numeric keypad; and [...]
So again, what are the UTF-16 codepoints for the up-arrow, the INS key, the
PAGE UP key, etc.? (Some wise-asses might try giving an answer for the DEL
key and call that a partial answer. Too late, this wise-ass has already
thought of that. My "etc." does not include the DEL key.)
Windows CE is off-topic for this newsgroup but it's good for a laugh.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wceshellui5/html/wce50lrfWMCHAR.asp
chCharCode = (TCHAR) wParam;
In Windows CE, TCHAR is always Unicode, so wParam is always converted from
Unicode to Unicode. Technically, no problem. This MSDN page uses the
(TCHAR) cast just to help confuse anyone who was trying to figure out the
Win32 version, where ANSI compilations are possible and TCHAR might be char
and this cast might yield half of a character.
OK, back to Win32. If someone knows the UTF-16 codepoints for the up-arrow,
the INS key, etc., then how should programmers use this information? The
answer obviously isn't VK_UP, VK_INSERT, etc., because their numeric values
are UTF-16 codepoints for some control characters that have existed longer
than PCs, PC keyboards, and Windows. Even VK_DELETE has value 0x2D whereas
UTF-16 for the DEL key is 0x7F. Is there a header file that defines
mnemonics for the UTF-16 values of these keys? Is there an MSDN page
documenting these defines?
(Also, good luck hunting for virtual key codes in MSDN. If you're lucky
then someone will point you to
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/WindowsUserInterface/UserInput/VirtualKeyCodes.asp
But you won't find it in the MSDN table of contents.)
.
- Follow-Ups:
- RE: WM_CHAR
- From: "Jeffrey Tan[MSFT]"
- RE: WM_CHAR
- Prev by Date: Re: Tools for CPU usage and Memory Usage
- Next by Date: 5 time shift remanent key mess
- Previous by thread: Re: Mirror Driver Architecture
- Next by thread: RE: WM_CHAR
- Index(es):
Relevant Pages
|