一个键盘钩子的小问题? ( 积分: 100 )

  • 主题发起人 主题发起人 maomaoel
  • 开始时间 开始时间
M

maomaoel

Unregistered / Unconfirmed
GUEST, unregistred user!
我写的一个键盘钩子程序<br>问题是按a里出来两个7,按f9时出来两个对话框,百思不得其解,请指教.<br>回调函数如下:<br>procedure hookproc(msgid,wparam,lparam:integer);stdcall;<br> &nbsp;var<br> &nbsp; &nbsp; keystate:tkeyboardstate;<br> &nbsp; &nbsp; presskey:array[0..1] of char;<br> &nbsp; &nbsp; focushwnd:dword;<br> &nbsp;begin<br><br> &nbsp; &nbsp; &nbsp;getkeyboardstate(keystate);<br> &nbsp; &nbsp; &nbsp;toascii(wparam,lparam,keystate,@presskey[0],0);<br> &nbsp; &nbsp; &nbsp;if presskey[0]='a' then<br> &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; focushwnd:=getfocus();<br> &nbsp; &nbsp; &nbsp; &nbsp; sendmessage(focushwnd,wm_ime_char,55,0);<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;if wparam=vk_f9 then<br> &nbsp; &nbsp; &nbsp;messagebox(0,'chenhui','chdg',0);<br> &nbsp; &nbsp; &nbsp;callnexthookex(hhook,msgid,wparam,lparam);<br> &nbsp;end;
 
我写的一个键盘钩子程序<br>问题是按a里出来两个7,按f9时出来两个对话框,百思不得其解,请指教.<br>回调函数如下:<br>procedure hookproc(msgid,wparam,lparam:integer);stdcall;<br> &nbsp;var<br> &nbsp; &nbsp; keystate:tkeyboardstate;<br> &nbsp; &nbsp; presskey:array[0..1] of char;<br> &nbsp; &nbsp; focushwnd:dword;<br> &nbsp;begin<br><br> &nbsp; &nbsp; &nbsp;getkeyboardstate(keystate);<br> &nbsp; &nbsp; &nbsp;toascii(wparam,lparam,keystate,@presskey[0],0);<br> &nbsp; &nbsp; &nbsp;if presskey[0]='a' then<br> &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; focushwnd:=getfocus();<br> &nbsp; &nbsp; &nbsp; &nbsp; sendmessage(focushwnd,wm_ime_char,55,0);<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;if wparam=vk_f9 then<br> &nbsp; &nbsp; &nbsp;messagebox(0,'chenhui','chdg',0);<br> &nbsp; &nbsp; &nbsp;callnexthookex(hhook,msgid,wparam,lparam);<br> &nbsp;end;
 
按下抬起都会调用钩子函数, &nbsp;if ((LParam shr 31) and 1) = 0 then 按下 else 抬起;
 
多谢<br>好了<br>接分
 
更正一下, 正确的应该是 if (lParam and $80000000 = 0) then 按下 else 抬起;<br>而原来的是 if ((LParam shr 31) and 1) = 0 then 之前抬起 else 之前按下;<br>
 
后退
顶部