#include
#include
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
int main()
{
while(1)
{
printf("鼠标左键是否按下:");
if(KEY_DOWN(VK_LBUTTON))printf("是");
else printf("否");
printf("\n");
printf("鼠标右键是否按下:");
if(KEY_DOWN(VK_RBUTTON))printf("是");
else printf("否");
printf("\n");
Sleep(2000);
}
return 0;
}
/*这两个函数可以检测键是否按下
SHORT GetAsyncKeyState(int vKey);
SHORT GetKeyState(int nVirtKey);*/
#include
#include
#include
int main()
{
//每隔Interval毫秒检测一次
const int Interval=150;
//共尝试检测Num次
const int Num=500;
const SHORT Mask=0x8000;
SHORT state;
int n=1,down=0,i;
for(i=1;i<=Num;i++)
{
//state=GetAsyncKeyState(VK_LBUTTON);
state=GetKeyState(VK_LBUTTON);
if(Mask==(state&Mask))
down=1;
else if(down)
{
printf("鼠标单击统计:%d\n",n++);
down=0;
}
Sleep(Interval);
}
system("PAUSE");
return 0;
}