现在的位置: 首页 > 综合 > 正文

鼠标轨迹记录和回复

2012年11月08日 ⁄ 综合 ⁄ 共 2185字 ⁄ 字号 评论关闭

unit mousereplay;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TForm6 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form6: TForm6;
  eventarr:array[0..1000] of EVENTMSG;
  eventlog:integer;
  playlog:integer;
  hhook,hplay:integer;
  bdelay:bool;

implementation

{$R *.dfm}

function playproc(icode:integer;wparam:WPARAM;lparam:LPARAM):LRESULT;stdcall;
begin
  result:=0;
  if icode<0 then
    result:=callnexthookex(hplay,icode,wparam,lparam)
  else if icode=HC_SYSMODALON then       //不允许回放

  else if icode=HC_SYSMODALOFF then  //允许回放

  else if icode=HC_GETNEXT then
  begin
     if bdelay then
     begin
        bdelay:=false;
        result:=50;
     end;
     pEVENTMSG(lparam)^:=eventarr[playlog];
  end
  else if icode=HC_SKIP then
  begin
    bdelay:=true;
    playlog:=playlog+1;
  end;

  if playlog>=eventlog then
  begin
    unhookwindowshookex(hplay);
  end;
end;

function hookproc(icode:integer;wparam:WPARAM;lparam:LPARAM):LRESULT;stdcall;
begin
  result:=0;
  if icode<0 then
    result:=callnexthookex(hhook,icode,wparam,lparam)
  else if icode=HC_SYSMODALON then //不允许记录

  else if icode=HC_SYSMODALOFF then //允许记录

  else if icode=HC_ACTION then
  begin
    eventarr[eventlog]:=peventMsg(lparam)^;
    inc(eventlog);
    if eventlog>=1000 then
    begin
      unhookwindowshookex(hhook);
    end;
  end;
end;

procedure TForm6.Button1Click(Sender: TObject);
begin
  eventlog:=0;
  //建立键盘鼠标操作链
  hhook:=setwindowshookex(WH_JOURNALRECORD,hookproc,hinstance,0);
  button2.Enabled:=true;
  button1.Enabled:=false;
  button3.Enabled:=false;
end;

procedure TForm6.Button2Click(Sender: TObject);
begin
  unhookwindowshookex(hhook);
  hhook:=0;
  button1.Enabled:=true;
  button2.Enabled:=false;
  button3.Enabled:=true;
end;

procedure TForm6.Button3Click(Sender: TObject);
begin
  playlog:=0;
  hplay:=setwindowshookex(WH_JOURNALRECORD,playproc,hinstance,0);
end;

procedure TForm6.FormCreate(Sender: TObject);
begin

  button2.Enabled:=false;
  button3.Enabled:=false;
end;

end.

------------------------------------------

不知为啥,回放不了

抱歉!评论已关闭.