C++|实时显示鼠标坐标
#include "pch.h" #include <iostream> #include<Windows.h> int main() { /* 功能: 移动鼠标获得当前鼠标坐标 */ LONG zx = -1; LONG zy = -1; POINT ptB = { 0, 0 }; while (1) { LPPOINT xy = &ptB; //位置变量 GetCursorPos(xy); //获取鼠标当前位置 //如果鼠标移动,(即当前的坐标改变则打印出坐标)打印出做坐标。 if ((zx != xy->x) || (zy != xy->y)) { printf("x=%d,y=%d x轴移动:%d, y轴移动:%d\n", xy->x, xy->y,(xy->x-zx), (xy->y - zy)); zx = xy->x; zy = xy->y; } } /* 功能: 获取鼠标坐标并移动鼠标 */ /*POINT p; while (1) { GetCursorPos(&p);//获取鼠标坐标 SetCursorPos(p.x + 3, p.y);//更改鼠标坐标 Sleep(10);//控制移动时间间隔 } return 0;*/ }
演示: