Reputation: 901
This is a continuation of my previous question: WinAPI: How to process keyboard input in custom edit control I felt i should put this in a different question as the nature of the question is a bit different.
So my program is receiving input now, but the input is a bit off. The best way to explain is to just show you the code and the result...
Here's the code that handles WM_CHAR:
case WM_CHAR:
{
TCHAR inc;
inc = MapVirtualKey(wParam, 2);
for(short i = 0; i < sizeof(TCHAR); i++)
{
unsigned char* x = reinterpret_cast<unsigned char*>(&inc);
printf("0x%.2X ", x[i]);
}
//InvalidateRect(t_hwnd, NULL, 0); // Repaint the window...
}
break;
The program is compiled as unicode so all function calls default to their unicode variants.
Here's the result of typing "asdf":
0x31 0x00 0x00 0x00 0x34 0x00 0x36 0x00
TCHAR is 2 bytes in size, so this comes out to "1\046"
Anyone know what the deal is here?
Upvotes: 0
Views: 1461
Reputation: 27460
MapVirtualKey accepts scan code for a key. But wParam in WM_CHAR is not a scan code - it is a char. You should use WM_KEYDOWN, wParam there is a scan code.
Links for you:
http://msdn.microsoft.com/en-us/library/ms646280(v=vs.85).aspx
http://msdn.microsoft.com/en-us/library/ms646276(v=vs.85).aspx
Upvotes: 1