How to send (keybd_event) Unicode Keys using C #

How can I send all Unicode code to 'keybd_event'.,

I found the Alt + Unicode (decimal) methods and C ++ code below

But I could not try C # ..

void TypingMessageFromCodePage(TCHAR* Message, UINT CodePage=0)
{
    TCHAR Word[2];
    TCHAR WordCode[64];
    char MultiByte[64];

    static const BYTE NumCode[10]={0x2D, 0x23, 0x28, 0x22, 0x25, 0x0C, 0x27, 0x24, 0x26, 0x21};
    int Length = wcslen(Message);

    for(int i=0; i<Length; i++)
    {
        Word[0] = Message[i];
        Word[1] = L'\0';

        WideCharToMultiByte(CodePage, 0, Word, -1, MultiByte, 64, NULL, NULL);
        _itow((int)(((~MultiByte[0])^0xff)<<8)+((~MultiByte[1])^0xff), WordCode, 10);

        keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 0), 0, 0);

        for(int j=0; j<wcslen(WordCode); j++)
        {
            keybd_event(NumCode[(int)WordCode[j]-48], MapVirtualKey(NumCode[(int)WordCode[j]-48], 0), 0, 0);
            keybd_event(NumCode[(int)WordCode[j]-48], MapVirtualKey(NumCode[(int)WordCode[j]-48], 0), KEYEVENTF_KEYUP, 0);
        }
        keybd_event(VK_MENU, MapVirtualKey(VK_MENU, 0), KEYEVENTF_KEYUP, 0);
    }
}
+4
source share
1 answer

Do not use keybd_event(). Use instead SendInput(). For this purpose has a flag KEYEVENTF_UNICODE. You can send actual UTF-16s with it (each charin .NET Stringis encoded as UTF-16 code). No need to simulate codes Alt+xxxxat all. For instance:

fooobar.com/questions/326439 / ...

fooobar.com/questions/1597555 / ...

fooobar.com/questions/1105937 / ...

+4
source

All Articles