简体   繁体   English

从C ++如何在我的计算机(而非窗口)上的桌面或Word文档中键入字符串

[英]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.

相关问题 使用C ++如何获取在桌面上打开的窗口的rgb值? - using c++ how do I get the rgb values of a window open on my desktop? C ++:如何检查我的窗口是否即将关闭? - C++: How do I check if my window is about to close? 如何将字符串添加到我的 struct 类型数组中,该数组同时包含 C++ 中的字符串和整数? - How do I add a string to my array of type struct which contains both strings and ints in c++? 如何找到对话框窗口在桌面上的位置? - How do I find the position of my Dialog Window on the desktop? 在C#中读取时,如何从C ++字符串中获得\\ 0 - How do I get \0 off my string from C++ when read in C# 如何使用C ++对Windows计算机上的远程计算机执行ping操作? - How can i ping remote computer on my Windows computer with c++? 在C ++中使用退出功能时,如何暂停命令窗口? - How do I pause my command window when using the exit function in C++? 如何在C ++中的字符串中找到完整的单词(不是它的一部分) - How do I find a complete word (not part of it) in a string in C++ Visual Studio 2019 C++ 桌面应用程序; 如何制作一个孩子 window? - Visual Studio 2019 C++ Desktop application; How do I make a child window? 如何在使用QQmlApplicationEngine时从C ++访问我的Window对象属性? - How can I access my Window object properties from C++ while using QQmlApplicationEngine?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM