Home > Backend Development > C++ > body text

How to Send Multiple Characters with SendInput()?

Susan Sarandon
Release: 2024-10-30 02:35:28
Original
709 people have browsed it

How to Send Multiple Characters with SendInput()?

Sending Multiple Characters with SendInput

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>
Copy after login

Important Note:

  • Virtual Keys: Use KEYEVENTF_UNICODE to use Unicode codepoints instead of virtual keys.
  • UNICODE Codepoints: Surrogate pairs are required to send characters outside the Basic Multilingual Plane (BMP).
  • Number of INPUT Structures: The first parameter of SendInput() specifies the number of INPUT structures.

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!