c++ - Sending Two or more chars using SendInput -


to send char, can use sendinput. how can use send more 1 char?

i tried code not send anything:

input in; in.type=input_keyboard; in.ki.wscan=0; in.ki.time=0; in.ki.dwextrainfo=0; in.ki.wvk=0x53+0x54;  sendinput(2,&in,sizeof(input)); 

so, right way?

the first parameter of sendinput() specifies how many input structures passing in. passing in 1, telling sendinput() passing in 2.

you cannot specify 2 separate virtual keys in single input. need declare array of multiple inputs, 1 each virtual key, , don't forget include 2 inputs each virtual key - 1 keydown event , 1 keyup event. so, in example, need 4 inputs send 2 virtual keys, shown in @user4581301's answer.

now, regarding keyeventf_unicode, don't use virtual keys it, use actual unicode codepoints instead, specified using utf-16 codeunits, 1 per input. means if want send unicode codepoint requires utf-16 surrogate pair, need 2 inputs, 1 high surrogate , 1 low surrogate. caveat not mentioned in sendinput() documentation, implied fact vscan field 16bit word, , keyeventf_unicode events generate wm_char messages, passes utf-16 surrogate codeunits separate messages.

so, send string of unicode characters using keyeventf_unicode, can this:

#include <vector> #include <string>  void sendinputstring(const std::wstring &str) {     int len = str.length();     if (len == 0) return;      std::vector<input> in(len*2);     zeromemory(&in[0], in.size()*sizeof(input));      int = 0, idx = 0;     while (i < len)     {         word ch = (word) str[i++];          if ((ch < 0xd800) || (ch > 0xdfff))         {             in[idx].type = input_keyboard;             in[idx].ki.wscan = ch;             in[idx].ki.dwflags = keyeventf_unicode;             ++idx;              in[idx] = in[idx-1];             in[idx].ki.dwflags |= keyeventf_keyup;             ++idx;         }         else         {             in[idx].type = input_keyboard;             in[idx].ki.wscan = ch;             in[idx].ki.dwflags = keyeventf_unicode;             ++idx;              in[idx].type = input_keyboard;             in[idx].ki.wscan = (word) str[i++];             in[idx].ki.dwflags = keyeventf_unicode;             ++idx;              in[idx] = in[idx-2];             in[idx].ki.dwflags |= keyeventf_keyup;             ++idx;              in[idx] = in[idx-2];             in[idx].ki.dwflags |= keyeventf_keyup;             ++idx;         }     }      sendinput(in.size(), &in[0], sizeof(input)); } 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -