D
david_sale
Unregistered / Unconfirmed
GUEST, unregistred user!
富翁里很多帖子提到可用SetwindowshookEX将 WH_KEYBORD设定钩子函数,代码放入一个DLL中得以监控到系统的所有键盘输入,但我希望将按键的键值改变,然后再传回系统处理,如我下例中希望将按1的键值全部改成输出2的键值,但不能成功。请大家指教<br><br>代码如下:<br><br>function keyboardhook(icode:integer;wparam:wparam;lparam:lparam):lresult;stdcall;export;<br>begin<br>if icode<0 then<br> result:=CallNextHookEx(oldhook,icode,wparam,lparam);<br> exit;<br>else<br> begin<br> if wparam=49 then //按键为1时改变键值为2<br> begin<br> wparam:=50;<br> result:=CallNextHookEx(oldhook,icode,wparam,lparam);<br> end;<br> <br> //showmessage(inttostr(wparam)+' '+ IntToHex(lparam,8));<br> //result:=CallNextHookEx(oldhook,icode,wparam,lparam);<br> end;<br>end;<br><br>function setkeyhook:bool;export;//加载钩子<br>begin<br>if oldhook=0 then<br> oldhook:=SetWindowsHookEx(WH_KEYBOARD,keyboardhook,HInstance,0);<br>result:=oldhook<>0;<br>end;<br><br>function endkeyhook:bool;export;<br>begin<br>if oldhook<>0 then unhookwindowshookex(oldhook);<br>oldhook:=0;<br>result:=oldhook=0;<br>end;