检测鼠标左键被按下:
KEY_DOWN(VK_LBUTTON)
得到鼠标按下时坐标:
POINT p;
GetCursorPos(&p);
cout << " x position:" << p.x << " y position: " << p.y << endl;
设置模拟点击的位置并模拟点击:
SetCursorPos(atoi(argv[1]), atoi(argv[2]));
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
完整程序:
#include<iostream>
#include<windows.h>
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
int main(int argc, char ** argv)
{
if (argc != 4)
{
cout << "Command Usage: MouseDetection.exe x_position y_position time(s).";
}
POINT p;
while (true)
{
#if 0
//Get current cursor position.
if (KEY_DOWN(VK_LBUTTON))
{