钩子高手请进来看看! 我也正好在研究钩子函数,大家研究研究[email protected] 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我也在研究这个呢,发给我看看[email protected] [email protected]一起学习,多多交流 我看了你的程序了,知道是什么地方出问题了。因为WH_KEYBOARD钩子要截获WM_KEYDOWN和WM_KEYUP,当F10被按下时,你的钩子函数被执行,AfxMessageBox了一下;F10弹起你的钩子函数又被执行,又AfxMessageBox了一下(这一下是不必要的)。程序改一下就行了。 if (((DWORD)lParam & 0x40000000)//判断是按下 && (HC_ACTION == nCode)) { switch (wParam) { case VK_F10: //AfxMessageBox("Caught the F10 key!"); bHandledKeystroke = TRUE; str.Format(_T("bHandledKeystroke%d"), bHandledKeystroke);AfxMessageBox(str); break; default : break ; } }//str.Format(_T("bHandledKeystroke%d"),// bHandledKeystroke);//AfxMessageBox(str); 这里移到上面去了,F10弹起这里也执行。 WM_KEYDOWN使bHandledKeystroke为1,而WM_KEYUP使bHandledKeystroke为0。 可是有一个问题,在这个函数(KbdHookProc)的最后还有一句:return (bHandledKeystroke ? TRUE : ::CallNextHookEx (ghKeyHook, nCode, wParam, lParam)); 它将视 bHandledKeystroke的值而做,我想要它做的是:当F10按下后,bHandledKeystroke为TRUE,然后钩子函数返回真,F10的功能失去;当按下其他键时,bHandledKeystroke为FALSE,则调用::CallNextHookEx (ghKeyHook, nCode, wParam, lParam),不让其他键失去作用。 可是现在的问题是当出了SWITCH循环后,由于WM_KEYUP的作用使bHandledKeystroke最终为0,这使得F10的功能并没有失去,如在VC环境下,F10仍然能调试。所以我想应该单独处理WM_KEYDOWN和WM_KEYUP消息,可是该怎么做呢?请指教! VC中的F10功能键捕捉的是WM_KEYDOWN消息,而你的程序捕捉的是WM_KEYUP,那当然过滤不去了。你应注意到,你的程序中有这个逻辑关系((DWORD)lParam & 0x40000000)),其意义就是当lParam的最高位为1时条件成立,即按键释放之时,具体你可以参阅MSDN。将程序改成如下,便可以过滤掉VC中的F10功能键:LRESULT EXPORTED_DLL_FUNCTION KbdHookProc (int nCode, WPARAM wParam, LPARAM lParam){CString str; BOOL bHandledKeystroke = FALSE; if (HC_ACTION == nCode) { switch (wParam) { case VK_F10: if(!((DWORD)lParam & 0x40000000)) { bHandledKeystroke = TRUE; str.Format(_T("Caught the F10 key!\nbHandledKeystroke%d"), bHandledKeystroke); AfxMessageBox(str); } break; default : break ; } } return (bHandledKeystroke ? TRUE : ::CallNextHookEx (ghKeyHook, nCode, wParam, lParam));} 技术分排名进入前10000名,散分 我用visual studio 2008开发了个activex,客户端安装不用下载.net 哈哈.光棍节散分...... 如何把数据写入access的ole字段。。 虚心的新手问个菜鸟问题 如何得到本机ip地址 多文档界面(MDI)的问题? 关于pppoe开发,给点思路就给分。 只能读1221条记录; ####### 第一次用VC写XML但不知道如何入手啊######## 各位帮我想想这个问题是为什么????? 校验是怎么回事?C语言的实现?
[email protected]
一起学习,多多交流
因为WH_KEYBOARD钩子要截获WM_KEYDOWN和WM_KEYUP,当F10被按下时,你的钩子函数被执行,AfxMessageBox了一下;F10弹起你的钩子函数又被执行,又AfxMessageBox了一下(这一下是不必要的)。程序改一下就行了。 if (((DWORD)lParam & 0x40000000)//判断是按下
&& (HC_ACTION == nCode))
{
switch (wParam)
{
case VK_F10:
//AfxMessageBox("Caught the F10 key!");
bHandledKeystroke = TRUE;
str.Format(_T("bHandledKeystroke%d"),
bHandledKeystroke);
AfxMessageBox(str);
break; default :
break ;
}
}
//str.Format(_T("bHandledKeystroke%d"),
// bHandledKeystroke);
//AfxMessageBox(str); 这里移到上面去了,F10弹起这里也执行。
可是有一个问题,在这个函数(KbdHookProc)的最后还有一句:
return (bHandledKeystroke ? TRUE : ::CallNextHookEx (ghKeyHook, nCode, wParam, lParam));
它将视 bHandledKeystroke的值而做,我想要它做的是:当F10按下后,bHandledKeystroke为TRUE,
然后钩子函数返回真,F10的功能失去;当按下其他键时,bHandledKeystroke为FALSE,则调用
::CallNextHookEx (ghKeyHook, nCode, wParam, lParam),不让其他键失去作用。
可是现在的问题是当出了SWITCH循环后,由于WM_KEYUP的作用使bHandledKeystroke最终为0,这使得
F10的功能并没有失去,如在VC环境下,F10仍然能调试。所以我想应该单独处理WM_KEYDOWN和WM_KEYUP消息,
可是该怎么做呢?请指教!
你应注意到,你的程序中有这个逻辑关系((DWORD)lParam & 0x40000000)),其意义就是当lParam的最高位为1时条件成立,即按键释放之时,具体你可以参阅MSDN。
将程序改成如下,便可以过滤掉VC中的F10功能键:
LRESULT EXPORTED_DLL_FUNCTION KbdHookProc
(int nCode, WPARAM wParam, LPARAM lParam)
{CString str;
BOOL bHandledKeystroke = FALSE; if (HC_ACTION == nCode)
{
switch (wParam)
{
case VK_F10:
if(!((DWORD)lParam & 0x40000000))
{
bHandledKeystroke = TRUE;
str.Format(_T("Caught the F10 key!\nbHandledKeystroke%d"), bHandledKeystroke);
AfxMessageBox(str);
} break; default :
break ;
}
}
return (bHandledKeystroke ?
TRUE :
::CallNextHookEx (ghKeyHook, nCode, wParam, lParam));
}