zoukankan      html  css  js  c++  java
  • hook鼠标键盘记录和回放

    unit Unit1;
    // download by http://www.codefans.net
    interface
    
    uses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;
    
    type
      TForm1 = class(TForm)
        btn1: TButton;
        btn2: TButton;
        btn3: TButton;
        procedure FormCreate(Sender: TObject);
        procedure btn1Click(Sender: TObject);
        procedure btn2Click(Sender: TObject);
        procedure btn3Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
      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
      //  canPlay:=0
      else if iCode = HC_SYSMODALOFF then
      //  canPlay:=1
      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
    //  recOK:=1;
      Result:=0;
      if iCode < 0 then
        Result := CallNextHookEx(hHook,iCode,wParam,lParam)
      else if iCode = HC_SYSMODALON then
    //    recOK:=0
      else if iCode = HC_SYSMODALOFF then
    //    recOK:=1
      else if (iCode = HC_ACTION) then begin
        EventArr[EventLog]:=pEventMSG(lParam)^;
        EventLog:=EventLog+1;
    
        if EventLog>=1000 then begin
          UnHookWindowsHookEx(hHook);
        end;
      end;
    end;
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      btn2.Enabled:=False;
      btn3.Enabled:=False;
    end;
    
    procedure TForm1.btn1Click(Sender: TObject);
    begin
        EventLog:=0;
      hHook:=SetwindowsHookEx(WH_JOURNALRECORD,HookProc,HInstance,0);
      btn2.Enabled:=True;
      btn1.Enabled:=False;
      btn3.Enabled:=False;
    end;
    
    procedure TForm1.btn2Click(Sender: TObject);
    begin
        UnHookWindowsHookEx(hHook);
      hHook:=0;
      btn1.Enabled:=True;
      btn2.Enabled:=False;
      btn3.Enabled:=True;
    end;
    
    procedure TForm1.btn3Click(Sender: TObject);
    begin
       PlayLog:=0;
      hPlay:=SetwindowsHookEx(WH_JOURNALPLAYBACK,PlayProc,
        HInstance,0);
    end;
    
    end.
    书搞进脑袋 创新 创造; 积极
  • 相关阅读:
    Python 操作Excel之通过xlutils实现在保留原格式的情况下追加写入数据
    【转载】Python字符串操作之字符串分割与组合
    【转】Python判断字符串是否为字母或者数字
    Appium 在测试android混合应用时,关于webview页面切换的那些事儿
    使用pip install XX 命令时报错
    Appium笔记(二) 丶Appium的安装
    Android SDK的下载与安装
    KlayGE 4.4中渲染的改进(五):OpenGL 4.4和OpenGLES 3
    最先进的开源游戏引擎KlayGE 4.4发布
    KlayGE 4.4中渲染的改进(四):SSSSS
  • 原文地址:https://www.cnblogs.com/tobetterlife/p/12170530.html
Copyright © 2011-2022 走看看