Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/141.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;鼠标功能没有响应,尝试创建单击模拟器 #包括 #包括 #包括 //无效鼠标跟踪器(点鼠标点、int noOfSaves、int delay) //{ // //} int main(int argc,char*argv[]) { std::cout>延迟; std::cout_C++_C_Winapi_Visual C++ - Fatal编程技术网

C++ C++;鼠标功能没有响应,尝试创建单击模拟器 #包括 #包括 #包括 //无效鼠标跟踪器(点鼠标点、int noOfSaves、int delay) //{ // //} int main(int argc,char*argv[]) { std::cout>延迟; std::cout

C++ C++;鼠标功能没有响应,尝试创建单击模拟器 #包括 #包括 #包括 //无效鼠标跟踪器(点鼠标点、int noOfSaves、int delay) //{ // //} int main(int argc,char*argv[]) { std::cout>延迟; std::cout,c++,c,winapi,visual-c++,C++,C,Winapi,Visual C++,使用SetCursorPos设置光标位置,然后使用mouse\u event发送鼠标按钮点击事件。以下是我的工作代码。您可以尝试一下 #include <Windows.h> #include <iostream> #include <conio.h> //void MouseRetracer(POINT mousePos, int noOfSaves, int delay) //{ // //} int main(int argc, char* ar

使用
SetCursorPos
设置光标位置,然后使用
mouse\u event
发送鼠标按钮点击事件。以下是我的工作代码。您可以尝试一下

#include <Windows.h>
#include <iostream>
#include <conio.h>

//void MouseRetracer(POINT mousePos, int noOfSaves, int delay)
//{
//  
//}

int main(int argc, char* argv[])
{
    std::cout << "Enter delay between 2 clicks... ";
    int delay;
    std::cin >> delay;
    std::cout << "Hover the mouse to the desired location and press 'k'...\n";
    //std::cin.get();
    std::cout << "Press ENTER to start taking inputs!!!" << std::endl;

    bool quit = true;
    int noOfSaves = 0;
    POINT mousePos[100];

    while (quit)
    {
        if (_kbhit())
        {
            char kbKey = _getch();
            if (kbKey == 'k')
            {
                GetCursorPos(&mousePos[noOfSaves]);
                std::cout << noOfSaves + 1 << " positions saved...\n";
                noOfSaves++;
            }
            if (kbKey == 'q')
                quit = false;
        }
    }

    std::cout << "DO NOT move mouse now!" << std::endl;
    //MouseRetracer(mousePos, noOfSaves, delay);
    for (int i = 0; i < noOfSaves; i++)
    {
        //std::cout << mousePos[i].x << '\t';
        Sleep(delay);

        mouse_event(MOUSEEVENTF_LEFTDOWN, mousePos[i].x, mousePos[i].y, NULL, NULL);
        mouse_event(MOUSEEVENTF_LEFTUP, mousePos[i].x, mousePos[i].y, NULL, NULL);

        std::cout << i + 1 << "th save clicked!\n";
    }

    /*std::cout << "Do this again? (y/n)\n";
    char repeat;
    std::cin >> repeat;

    switch (repeat)
    {
    case 'y':
        system("cls");
        break;
    case 'Y':
        system("cls");
        break;
    default:
        return 0;
    }*/

    return 0;
}
for(int i=0;iSTD::请考虑用可运行代码发布一个问题,这样人们就可以更容易地处理问题。否则,我们只需猜测您想要什么。请检查“dBoY,现在您可以检查一下吗?”,我添加了完整的代码。“这个函数已经被取代了。但它也适用于使用
POINT mousePos;
的其他程序。定义
POINT mousePos[100]
似乎就解决了这个问题。
for (int i = 0; i < noOfSaves; i++)
{
    Sleep(delay);

    SetCursorPos(mousePos[i].x, mousePos[i].y);

    mouse_event(MOUSEEVENTF_LEFTDOWN, mousePos[i].x, mousePos[i].y, NULL, NULL);
    mouse_event(MOUSEEVENTF_LEFTUP, mousePos[i].x, mousePos[i].y, NULL, NULL);

    std::cout << i + 1 << "th save clicked!\n";
}