本帖最后由 Croper 于 2019-3-23 19:10 编辑
#include <windows.h>后可以使用SetCursorPos()和mouse_event(),
不过单纯模拟鼠标事件我建议是用autohotkey,毕竟是专业的。
或者使用Spy++获取窗口句柄并使用SendMessage,这样可以在一定程度上实现后台运行
这是我minecraft拿来挂机钓鱼用的#include <windows.h>
#include <iostream>
using namespace std;
char MinecraftClassName[] = "GLFW30";
int main()
{
HWND hwnd;
TCHAR sz[256];
hwnd = FindWindow(MinecraftClassName, NULL);
GetWindowText(hwnd, sz, 256);
cout << "Window Caption=" << sz << endl;
cout << "Window Handle=" << hwnd << endl;
int i = 0;
while (true)
{
WPARAM wp = (i++)+ 0x30;
if (i > 3) i = 0;
SendMessage(hwnd, WM_KEYDOWN, wp, 0);
Sleep(50);
SendMessage(hwnd, WM_KEYUP, wp, 0);
Sleep(100);
for (int i = 0; i < 1; ++i)
{
SendMessage(hwnd, WM_RBUTTONDOWN, 0, 0);
Sleep(50);
SendMessage(hwnd, WM_RBUTTONUP, 0, 0);
Sleep(450);
}
}
}
|