0

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?

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Actually, MapVirtualKey takes both scan codes and virtual key codes. It turns out i misread the documentation and that WM_CHAR returns a character code, not a virtual key code. Still, thanks for clarifying. ^_^

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.