键盘钩子特别烦人,一般说来如果没有特别的判断条件的话,响应函数会响应两次,一次是键盘按下时,另外一次是键盘弹起时,所以如下面所示的响应函数:
LRESULT CALLBACK KeyboardProc(
int code, // hook code
WPARAM wParam, // virtual-key code
LPARAM lParam // keystroke-message information
)
{
if (!(lParam & 0xA0000000))
{
switch (wParam)
{
case VK_SPACE:
AfxMessageBox("程序被调用!");
break;
default:
break;
}
}
return 1;
}
只有加了一个判断条件if (!(lParam & 0xA0000000))才能行,但是这个判断条件是什么意思呢???
LRESULT CALLBACK KeyboardProc(
int code, // hook code
WPARAM wParam, // virtual-key code
LPARAM lParam // keystroke-message information
)
{
if (!(lParam & 0xA0000000))
{
switch (wParam)
{
case VK_SPACE:
AfxMessageBox("程序被调用!");
break;
default:
break;
}
}
return 1;
}
只有加了一个判断条件if (!(lParam & 0xA0000000))才能行,但是这个判断条件是什么意思呢???
如果是按键按下后发送的消息,30位为1,如果是按键抬起后30位为1;
31位
指定转变状态:31位为0时候,按键正在被按下,为1时候,按键正在被释放
Specifies the previous key state. The value is 1 if the key is down before the message is sent; it is 0 if the key is up;第31位msdn的解释为:Specifies the transition state. The value is 0 if the key is being pressed and 1 if it is being released.
所以代替0xA0000000的数可以是0x40000000或者0x80000000.