记录键盘和鼠标的动作?然后保存下来?

解决方案 »

  1.   

    library hook;
    uses
      windows;{$R *.res}
    var
    hhk1,hhk2:hhook;////////////////
    procedure saveit(wparam,lparam:integer;mouseorkeyboard:boolean);
    begin
    //  在这里写保存的代码。
    end;
    function mousehookproc(ncode:smallint;wparam,lparam:integer):integer;stdcall;
    begin
      result:=0;
      try
        save(wparam,lparam,true);
      finally
      if ncode<0 then
       result:=callnexthookex(hhk2,ncode,wparam,lparam);
      end;end;
    function keyboardhookproc(ncode:smallint;wparam,lparam:integer):integer;stdcall;
    begin
      try
      result:=0;
      save(wparam,lparam,false);
      finally
      if ncode<0 then
       result:=callnexthookex(hhk1,ncode,wparam,lparam);
      end;
    end;
    procedure endhook;stdcall;
    begin
      unhookwindowshookex(hhk1);
      unhookwindowshookex(hhk2);end;
    procedure beginhook;stdcall;
    begin
      hhk1:=setwindowshookex(WH_KEYBOARD,@keyboardhookproc,hinstance,0);
      hhk2:=setwindowshookex(WH_MOUSE,@mousehookproc,hinstance,0);
    end;exports
    beginhook,
    endhook;
    end.
    ///////////////////////////////////////////////////////
    unit Main;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        Button2: TButton;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    var
      Form1: TForm1;implementation
    uses
    debug_san;
    {$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var
    h:cardinal;
    proc:tprocedure;
    begin
      h:=loadlibrary('hook.dll');
      try  proc:=getprocaddress(h,'beginhook');  proc;  finally
      freelibrary(h);
      end;end;procedure TForm1.Button2Click(Sender: TObject);
    var
    h:cardinal;
    proc:tprocedure;
    begin
      h:=loadlibrary('hook.dll');
      try
      proc:=getprocaddress(h,'endhook');
      proc;
      finally
      freelibrary(h);
      end;end;
    end.