头文件
#include<Windows.h>
获取位置
POINT P;
GetCursorPos(&P);
移动
int x = 123;
int y = 321;
SetCursorPos(x, y);
判断点击
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
if (KEY_DOWN(VK_LBUTTON))
cout << "Left click" << endl;
if (KEY_DOWN(VK_RBUTTON))
cout << "Right click" << endl;
if (KEY_DOWN(VK_MBUTTON))
cout << "Mid click" << endl;
模拟点击
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0);
总代码
#include<Windows.h>
#include<iostream>
using namespace std;
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
void GetPosition() {
POINT P;
GetCursorPos(&P);
}
void SetPosition() {
SetCursorPos(100, 50);
}
void IsClick() {
while (true) {
if (KEY_DOWN(VK_LBUTTON))
cout << "Left click" << endl;
if (KEY_DOWN(VK_RBUTTON))
cout << "Right click" << endl;
if (KEY_DOWN(VK_MBUTTON))
cout << "Mid click" << endl;
}
}
void Click() {
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0);
}
int main() {
return 0;
}