[英]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. 到目前为止,我还没有找到c ++如何将鼠标移动到x和y以及左右单击的位置。 I cannot seem to figure out how to click on something and then type from c++ .
我似乎无法弄清楚如何单击某些内容,然后从c ++键入内容。 If I had a word document up I want to be able to click it, open it and type something into it.
如果我有一个Word文档,我希望能够单击它,将其打开并在其中键入一些内容。 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
SendInput on MSDN MSDN上的SendInput
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));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.