// 检测numlock状态.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include"windows.h"
int main()
{
printf_s("get into main \n");
bool num_light_on = ((GetKeyState(VK_NUMLOCK) & 1) != 0);
//GetKeyState的高位表示此键是否按下 低位表示指示灯状态
if (num_light_on)
{
printf_s("num light is on \n");
}
else
{
printf_s("num light is off \n");
}
_gettch();
while (1) //观测 GetKeyState(VK_NUMLOCK) 的值
{
//short x;
printf_s("GetKeyState(VK_NUMLOCK) = %x \n", GetKeyState(VK_NUMLOCK));
Sleep(250);
}
//经测试 以无符号16进制 %x 来表示GetKeyState(VK_NUMLOCK) , 得到的结果是以下4种状态
//ffffff81 , 1 , ffffff80 , 0
_gettch();
return 0;
}