Mouse

老子叫甜甜 提交于 2019-12-17 22:44:50

头文件

#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;
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!