程序在对mouse_event的 Windows API 调用中冻结
Program is freezing on Windows API call to mouse_event
我正在尝试编写一个自动点击器机器人,但我不知道为什么程序在我运行时会阻塞。当程序进入cliquer()
时会发生这种情况。
是的,我是一名学生,所以我是一个初学者,如果你问的话,我确实是法国人。
谢谢你给我一个答案。
#include <iostream>
#include <ctime>
#include <windows.h>
using namespace std;
void cliquer();
int main()
{
time_t time_to_run;
time_t ac_time;
time_t time_left;
time(&ac_time); // Actualiser le temps
cout << "Hello, wanna cheat on Voltaire ?" << endl;
cout << "For how much time do you want to run it (s) ?" << endl;
cin >> time_to_run;
time(&ac_time); // Actualiser le temps
time_to_run = ac_time + time_to_run; // Le temps à executer = temps actuel + temps demandé
while(ac_time < time_to_run)
{
time(&ac_time); // Actualiser le temps
time_left = time_to_run - ac_time;
//if(time_left <= 18000) // Si supérieur à 5min
//{
cout << "TIME LEFT : " << time_left << endl;
//}
Sleep(100);
cliquer();
}
return 0;
}
//---------------------------------------------------------------------------------------------------------------------------------------
void cliquer()
{
mouse_event(MOUSEEVENTF_LEFTDOWN, 957, 396, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 957, 396 , 0, 0);
}
冻结的原因是您的鼠标焦点位于控制台中。您可以添加ShowWindow(GetConsoleWindow(), SW_MINIMIZE)
以最小化控制台,以避免冻结。
mouse_event已经过时了。请使用发送输入。
这是您可以参考的示例:
#include <iostream>
#include <ctime>
#include <windows.h>
using namespace std;
time_t time_to_run;
time_t ac_time;
time_t time_left;
HWND hwnd;
void autoclick()
{
INPUT input[2];
ZeroMemory(input, sizeof(INPUT) * 2);
input[0].mi.dx = input[1].mi.dx = 945;
input[0].mi.dy = input[1].mi.dy = 500;
input[0].type = input[1].type = INPUT_MOUSE;
input[0].mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
input[1].mi.dwFlags = MOUSEEVENTF_LEFTUP;
time(&ac_time);
time_to_run = ac_time + time_to_run;
while (ac_time < time_to_run)
{
time(&ac_time); // Actualiser le temps
time_left = time_to_run - ac_time;
cout << "TIME LEFT : " << time_left << "s"<<endl;
SendInput(2, input, sizeof(INPUT));
Sleep(100);
}
}
int main()
{
hwnd = GetConsoleWindow();
cout << "Hello, wanna cheat on Voltaire ?" << endl;
while (1)
{
ShowWindow(hwnd, SW_RESTORE);
cout << "For how much time do you want to run it (s) ?" << endl;
cin >> time_to_run;
ShowWindow(hwnd, SW_MINIMIZE);
autoclick();
}
return 0;
}
相关文章:
- 在Windows 10上使用Visual Studio 2019构建的Tesseract API c ++程序在Wind
- 如何使用Windows API C++更改已创建的文件夹/目录安全权限
- C++Windows API MOUSEEVENTF_XDOWN,MOUSEEVENTF_XUP不起作用
- Windows (COM) API 的行为不同,没有特定的库
- 如何在 Windows API 中更改系统范围的多个游标
- 为什么我在 Windows API 中得到对 TextOut() 函数的未定义引用?
- 谁拥有作为指向 Windows API 函数的指针传递的值?
- 使用 Windows API c++ 的键盘输入
- 程序在对mouse_event的 Windows API 调用中冻结
- 当PSO细粒度策略对使用AdsGetObject MSDN API的Windows操作系统生效时,如何获取用户密码到期日
- Windows上的Flite API错误
- 等效的Windows API与Power shell get-physicaldisk命令
- sf::Windows上的音乐:api-ms-win-crt-locale-l1-1-0.dll:无法打开共享对象文件
- 无法在 Windows 10/Visual C++ 2017 上使用 tensorflow C++ API tensor
- 是否有一个Windows驱动程序函数可以执行Windows文件api SeFileAttributes的等效功能
- Windows 文件系统 API 不同的输出
- 需要更好地了解使用 Windows API 的智能指针
- 如何检查 CNG Windows API 是否返回符合 FIPS 的算法实现
- 跨平台API开发Windows,Linux等
- 当std::cout被调用时,使用了什么外部API ?(Windows)