为了一个键盘钩子,提问了N次没人理,查资料N*N*N*N*N*N次找不到。搞了五天,完全白忙,就要疯啦一见到电脑就烦,
真想砸了 扔到坛上
大家快来呀,高手救命,非高手看热闷,看完拿一块显卡,硬盘马达,显视屏碴子跑.....不满意扔回来我
俺不干了唉
真想砸了 扔到坛上
大家快来呀,高手救命,非高手看热闷,看完拿一块显卡,硬盘马达,显视屏碴子跑.....不满意扔回来我
俺不干了唉
解决方案 »
- lib 中同名函数/类的连接问题
- 唉!原来五颗星变成只有一颗星了! 伤心之余只好放分!
- 想知道qq中人物秀中,图片的组合是用程序实现的还是用美工做好的!!!
- 我用vc写的dll中的一个接口函数,在调用时报地址错误!请问我这么写有错误吗?
- CSocket的问题
- 用哪种数据库技术可以使分发的安装程序最小???
- 有人有开发大型文件传输软件的经验吗?急需您的帮助。VC的。
- 光盘上的程序拷到机子上,为什么class view 里的东东不见了?
- _RecordsetPtr 如何更新 记录
- 如何使应用程序打开时不在任务栏中出现!
- 求助,在Berkeley DB上开发一个应用,大家有什么建议么?(在CSDN上找了半天,也没搞定)
- 请问各位有关socket关闭的问题。
{
if(nCode>=0)
{
if((lParam&0xc000ffff)==1) //aaaaaaaaaaaaaaaaa
::PostMessage(m_h0Main,WM_HOOK_KEYDOWN,wParam,lParam); }
return CallNextHookEx(hKeyHook,nCode,wParam,lParam);
}
其中aaaaaaaaaaaaa分别换成了:
lParam &0x80000000 lParam & 0x40000000 lParam & 0xA0000000 lParam & 0xc000ffff不管那个,运行起来有时很正常,有时却会:莫名奇妙地,按一次键却钩到两个“按下”特别是按得快的话,一团糟
位操作搞烦了,再来用位段替换掉 lParam
如下:struct Lparam_Bit_Struct
{
unsigned Repeat_Code :16; //0~15 位
unsigned Scan_Code :8; //16~23
unsigned IsExtemded_Key :1; // 24
unsigned Reserve_Data :4; // 25~28
unsigned IsALT_Down :1; // 29
unsigned Pre_Key_State :1; // 30
unsigned This_Key_State :1; // 31
};Lparam_Bit_Struct *LparamBStruct;
LparamBStruct=(Lparam_Bit_Struct *)(&lParam);if(LparamBStruct->This_Key_State==0)
{
::PostMessage(m_h0Main,WM_HOOK_KEYDOWN,wParam,lParam);
}一样!!!—*……*%狂晕晕晕晕晕晕晕晕晕晕晕晕晕晕晕晕呀,我砸电脑,靠lParam 里面究境放了什么东西&^*%&^$^%$^&参看:
lParam
击键信息产生多个标志的组合值,包括重复击键次数, 键盘扫描代码, 功能键标志位等:
0–15 位:重复击键次数;
16–23位:键盘扫描代码;
24 位:功能键或小键盘标志位,1为有效;
29 位:alt键是否按下,1为按下;
30 位:前一次击键的状态,1为按下,0为放开
31 位:本次击键状态,0为正在按下,1为正在放开msdn e 文原解:
lParam
[in] Specifies the repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag. This parameter can be one or more of the following values. Value Description
0–15 Specifies the repeat count. The value is the number of times the keystroke is repeated as a result of the user's holding down the key.
16–23 Specifies the scan code. The value depends on the original equipment manufacturer (OEM).
24 Specifies whether the key is an extended key, such as a function key or a key on the numeric keypad. The value is 1 if the key is an extended key; otherwise, it is 0.
25–28 Reserved.
29 Specifies the context code. The value is 1 if the ALT key is down; otherwise, it is 0.
30 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 Specifies the transition state. The value is 0 if the key is being pressed and 1 if it is being released.
问题解决LRESULT CALLBACK KeyBoardProc(int nCode,WPARAM wParam, LPARAM lParam )
{
if(nCode>=0) ////// 这里
{
if((lParam&0xc000ffff)==1) //aaaaaaaaaaaaaaaaa
::PostMessage(m_h0Main,WM_HOOK_KEYDOWN,wParam,lParam); }
return CallNextHookEx(hKeyHook,nCode,wParam,lParam);
}LRESULT CALLBACK KeyBoardProc(int nCode,WPARAM wParam, LPARAM lParam )
{
if(nCode==HC_ACTION) // 改 (宏 HC_ACTION==0)
{
if((lParam&0xc000ffff)==1) //aaaaaaaaaaaaaaaaa
::PostMessage(m_h0Main,WM_HOOK_KEYDOWN,wParam,lParam); }
return CallNextHookEx(hKeyHook,nCode,wParam,lParam);
}
我看到很多的键盘钩子例子都是写成 if(nCode>=0) 误人子弟呀如果用 if(nCode>=0) 的话,若按键速度很快,你可能会收到两个KEYDOWN 与 KEYUP 特别是键盘钩子DLL 所注入的进程反应太慢的话
好像原理是这样的,当 nCode==HC_NOREMOVE (宏HC_NOREMOVE==3) 时,if(nCode>=0) 为真,即我的程序收到KEYDOWN,而实际上,nCode==HC_NOREMOVE 表示 上一次按键消息还在系统队列里.