头文件
#include<Windows.h>
获取位置
POINT P;
GetCursorPos(&P);
//P.x
//P.y
移动
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;
模拟点击
//Left click
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
//Right click
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);
//cout << P.x << endl;
//cout << P.y << endl;
}
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() {
//Left click
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
//Right click
mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0);
}
int main() {
return 0;
}
来源:CSDN
作者:qq_41823120
链接:https://blog.csdn.net/qq_41823120/article/details/103586316