2

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
}
4

1 回答 1

4

尝试使用 SendInput

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));
于 2013-06-02T22:36:18.983 回答