鼠标轨迹记录和回复

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.



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

不知为啥,回放不了


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值