1

I'm hooking windows WM_CHAR message. When I'm replacing (in hook) given char code to something simple like 'a', every character I type is turning into a. And that's ok. But when I'm trying to send unicode character, like ф ('ф'.charCodeAt(0) gives 1092, so I'm replacing 'a' to 1092 in my code), all letters are turned into D. Also, when I type Alt+1092 in every text editor I'm getting D. Why? And can I send unicode char using WM_CHAR? Documentation says "The WM_CHAR message uses Unicode Transformation Format (UTF)-16.".

LRESULT CALLBACK Proc(int code, WPARAM wParam, LPARAM lParam)
{
    if(code >= HC_ACTION)
    {
        MSG* msg=(MSG *)lParam;
        if(msg->message==WM_CHAR)
        {
            int charCode = msg->wParam;
            if(IsCharLower(charCode))
            {
                charCode = 1092;
                msg->wParam=(WPARAM)charCode;
            }
        }
    }

    return CallNextHookEx(hHook, code, wParam, lParam);
};
4
  • Is the window receiving this message created as a Unicode window? You can check by calling IsWindowUnicode(msg->hwnd). It appears that the upper byte of wParam gets masked out: Character 'ф' is U+0444, character 'D' is U+0044. Aug 13, 2014 at 11:27
  • 1
    IsWindowUnicode returns true. Yes I realized this about upper byte, and wanted to simulate typing any unicode char directly from keyboard, and use Spy++ to know what message it is, but as I said in post: Alt+1092 also don't work :| So I have no idea how can I simulate it.
    – John
    Aug 13, 2014 at 11:56
  • Why are you using messages to simulate keyboard input, instead of using SendInput() or similar function that are designed to handle this for you? Aug 13, 2014 at 16:44
  • 1
    Because I want to use replace typed chars, not add new.
    – John
    Aug 13, 2014 at 18:51

0

Your Answer

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

Browse other questions tagged or ask your own question.