滑鼠軌跡記錄和回複

來源:互聯網
上載者:User

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.

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

不知為啥,回放不了

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.