C++ 将控制台数据输出到另一程序并执行

请问如何将每次鼠标点击的坐标输出到另一个程序的输入框中
现在写的代码使用点击的鼠标坐标输出到cmd中,想将每一次点击的输出到网络调试助手并执行,请问该怎么实现,尝试了一下postmessage但是没有成功。

#include "Analysismovement.h"
#include
#include
#include
#include
#include "opencv2\highgui\highgui_c.h"
#include

#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0) //用来检测按键的点击事件

using namespace std;
using namespace cv;

POINT p;
HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
HWND h = GetForegroundWindow();
CONSOLE_FONT_INFO consoleCurrentFont;

int Analysismovement::frameCHA() {
VideoCapture capture(1); //open cam

if (!capture.isOpened()) { //test cam
    cout << "cam open error" << endl;
    return 0;
}

Mat frame; //cam write in
Mat temp; //last frame
Mat result; // result of Movedetect
int frameNum = 1; // currunt frame

ShellExecute(NULL, L"open", L"D://biorobtics//robotarm//cx//NetAssist.exe", NULL, NULL, SW_SHOWNORMAL);

while (true) { // cycle frame
    capture >> frame;
    if (frame.empty()) {
        cout << "frame is empty" << endl;
        break;
    }

    //first frame
    if (frameNum == 1) {
        result = Movedetect(frame, frame);
    }

    else {
        result = Movedetect(temp, frame);
    }
    namedWindow("cam", WINDOW_NORMAL);
    imshow("cam", result);
    
    HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
    DWORD mode;
    GetConsoleMode(hStdin, &mode);
    mode &= ~ENABLE_QUICK_EDIT_MODE;
    SetConsoleMode(hStdin, mode);

    if (KEY_DOWN(VK_RBUTTON)) {              //Right button 
        POINT p;
        GetCursorPos(&p);
        HWND hWnd = (HWND)cvGetWindowHandle("cam");
        ScreenToClient(hWnd, &p);
        GetCurrentConsoleFont(hOutput, FALSE, &consoleCurrentFont); //获取字体信息
        int x = p.x /= consoleCurrentFont.dwFontSize.X;
        int y = p.y /= consoleCurrentFont.dwFontSize.Y;
        printf("key down (%d,%d)\n", x, y);
    }
    Sleep(50);



    if (waitKey(20) == 27) {
        cout << "Quit" << endl;
        break;
    }
    temp = frame.clone();
    frameNum++;
}

}

Mat Analysismovement::Movedetect(Mat temp, Mat frame) {
Mat result = frame.clone();

//1.covert the cam to gray
Mat gray1, gray2;
cvtColor(temp, gray1, COLOR_BGR2GRAY);
cvtColor(frame, gray2, COLOR_BGR2GRAY);

//2.subtract 2 frame
Mat diff;
absdiff(gray1, gray2, diff);
//imshow("sub", diff);

//3.color
Mat diff_thresh;
threshold(diff, diff_thresh,50,255,THRESH_BINARY);
//imshow("color", diff_thresh);

//4.kernel transfer
Mat kernel_ercode = getStructuringElement(MORPH_RECT, Size(3, 3));
Mat kernel_dilate = getStructuringElement(MORPH_RECT, Size(18, 18));

//5. Corrosion transformation
erode(diff_thresh, diff_thresh, kernel_ercode);

//6.Dilate transformation
dilate(diff_thresh, diff_thresh, kernel_dilate);

//7.search and draw outline
vector>contours;
findContours(diff_thresh, contours, RETR_EXTERNAL, CHAIN_APPROX_NONE);
drawContours(result, contours, -1, Scalar(0, 0, 255), 2);

//8.outline
vectorboundRect(contours.size());
for (int i = 0; i < contours.size(); i++) {
    boundRect[i] = boundingRect(contours[i]);
    rectangle(result, boundRect[i], Scalar(0, 255, 0), 2);
}
return result;

}

鼠标点击代码参考了 https://blog.csdn.net/wangxun20081008/article/details/113915805

使用socket通讯吧,你的程序(udp 客户端)通过socket,将鼠标坐标参数发送给NetAssist(udp 服务端)。

百度搜”SendInput“,应该有一大堆例子。

先用Findwindow,找到类型为edit的窗口,用SendMessage输到窗口上

可不可以输出到一个文件里,然后再让那个程序从这个文件里读入?