键盘线程钩子的问题,急等求助!(200分)

  • 主题发起人 主题发起人 zhengdehei
  • 开始时间 开始时间
Z

zhengdehei

Unregistered / Unconfirmed
GUEST, unregistred user!
function StartHook(lpHwnd: Cardinal): Boolean;<br>var<br>&nbsp; hThread: Cardinal;<br>begin<br>&nbsp; Result:= false;<br>&nbsp; if hNextKeyHookProc &lt;&gt; 0 then exit;<br>&nbsp; hThread:= GetWindowThreadProcessId(lpHwnd);<br><br>&nbsp; hNextKeyHookProc:= SetWindowsHookEx(WH_KEYBOARD, @KeyHookProc, HInstance, hThread);<br>&nbsp; Result:= hNextKeyHookProc &lt;&gt; 0;<br>end;<br><br>function KeyHookProc(iCode: integer; wParam: wParam; lParam: lParam):LResult; stdcall;//HOOK过程<br>begin<br>&nbsp; if iCode &lt; 0 then begin<br>&nbsp; &nbsp; Result:= CallNextHookEx(hNextKeyHookProc, iCode, wParam, lParam);<br>&nbsp; &nbsp; exit;<br>&nbsp; end;<br><br>&nbsp; Result:= 1;<br>&nbsp; if (iCode = HC_Action) and ((lParam and _KeyPressMask) = 0) then begin<br>&nbsp; &nbsp; case wParam of<br>&nbsp; &nbsp; &nbsp; 处理....<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>end;<br><br>这个线程键盘钩子用起一直很正常,但是重复给多个程序加载次数过多后,会出现StartHook失败,并且操作系统很多菜单点不下去,很多带密码文本框的地方,无法输入字符。<br><br>这不是什么盗号程序,只是出现了以上的现象。大概重复30次以上,就有可能出现。望高手指出错误,感谢不尽
 
改成这样看看.<br>function KeyHookProc(iCode: integer; wParam: wParam; lParam: lParam):LResult; stdcall;//HOOK过程<br>begin <br>&nbsp; Result:= 1;<br>&nbsp; if (iCode = HC_Action) and ((lParam and _KeyPressMask) = 0) then begin<br>&nbsp; &nbsp; case wParam of<br>&nbsp; &nbsp; &nbsp; 处理....<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>&nbsp; &nbsp; Result:= CallNextHookEx(hNextKeyHookProc, iCode, wParam, lParam);<br>end;
 
其实平时用起都没问题,就是加载次数多了,就无效了。请过路的高手指点一下
 
后退
顶部