C++中获取鼠标点击事件 10
我要侦测点击鼠标左键的这个动作,然后在此之后做一些事情,我该怎么办? 展开
直接给代码:
#include<iostream>
#include<windows.h>
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0) //必要的,我是背下来的
using namespace std;
int main(){
while(1){
printf("鼠标左键是否按下:");
if(KEY_DOWN(MOUSE_MOVED))printf("是");
else printf("否");
printf("\n");
printf("鼠标右键是否按下:");
if(KEY_DOWN(MOUSE_EVENT))printf("是");
else printf("否");
printf("\n");
printf("鼠标滚轮键是否按下:");
if(KEY_DOWN(MOUSE_WHEELED))printf("是");
else printf("否");
printf("\n");
Sleep(20);//循环时间间隔,防止太占内存
system("cls");//清屏
}
return 0;
}