Question:
How can SendInput be used to send more than one character?
Answer:
SendInput() accepts multiple INPUT structures. Each INPUT structure represents a single key event (press or release). To send multiple characters, create an array of INPUT structures and specify the correct virtual key codes or Unicode codepoints.
Correct Code for Sending Two Characters:
<code class="c++">#include <array> int main() { array<INPUT, 4> in; // KEYEVENTF_UNICODE specifies using Unicode codepoints in[0].type = INPUT_KEYBOARD; in[0].ki.dwFlags = KEYEVENTF_UNICODE; in[0].ki.wScan = 0; in[0].ki.time = 0; in[0].ki.dwExtraInfo = 0; in[0].ki.wVk = VkKeyScanW('S'); // 'S' character in[1].type = INPUT_KEYBOARD; in[1].ki.dwFlags = KEYEVENTF_UNICODE | KEYEVENTF_KEYUP; in[1].ki.wScan = 0; in[1].ki.time = 0; in[1].ki.dwExtraInfo = 0; in[1].ki.wVk = VkKeyScanW('S'); // 'S' character in[2].type = INPUT_KEYBOARD; in[2].ki.dwFlags = KEYEVENTF_UNICODE; in[2].ki.wScan = 0; in[2].ki.time = 0; in[2].ki.dwExtraInfo = 0; in[2].ki.wVk = VkKeyScanW('T'); // 'T' character in[3].type = INPUT_KEYBOARD; in[3].ki.dwFlags = KEYEVENTF_UNICODE | KEYEVENTF_KEYUP; in[3].ki.wScan = 0; in[3].ki.time = 0; in[3].ki.dwExtraInfo = 0; in[3].ki.wVk = VkKeyScanW('T'); // 'T' character SendInput(in.size(), &in[0], sizeof(INPUT)); return 0; }</code>
Important Note:
The above is the detailed content of How to Send Multiple Characters with SendInput()?. For more information, please follow other related articles on the PHP Chinese website!