简体   繁体   中英

from C++ how do I type a string to my desktop or word document on my computer (not window)

So far from c++ I found how to move the mouse to position x and y and to right and left click. I cannot seem to figure out how to click on something and then type from c++ . If I had a word document up I want to be able to click it, open it and type something into it. Thanks in advance !

#include <windows.h>
#include <iostream>
#include <ctime>
using namespace std;

int main ()
{
SetCursorPos(97,758);
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); // Left click
Sleep( 1000 );
SetCursorPos(418,657);
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); 
SetCursorPos(266,34);
Sleep( 1000 );
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); 
//right here is where I would like to type something to the document
}

try using SendInput

SendInput on MSDN

    INPUT ip;

    // Set up a generic keyboard event.
    ip.type = INPUT_KEYBOARD;
    ip.ki.wScan = 0; // hardware scan code for key
    ip.ki.time = 0;
    ip.ki.dwExtraInfo = 0;

    // Press the "A" key
    ip.ki.wVk = 0x41; // virtual-key code for the "a" key
    ip.ki.dwFlags = 0; // 0 for key press
    SendInput(1, &ip, sizeof(INPUT));

    // Release the "A" key
    ip.ki.dwFlags = KEYEVENTF_KEYUP; // KEYEVENTF_KEYUP for key release
    SendInput(1, &ip, sizeof(INPUT));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM