⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.~pas

📁 消息控制记录鼠标动作
💻 ~PAS
字号:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(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
  Button2.Enabled:=False;
  Button3.Enabled:=False;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  EventLog:=0;
  hHook:=SetwindowsHookEx(WH_JOURNALRECORD,HookProc,HInstance,0);
  Button2.Enabled:=True;
  Button1.Enabled:=False;
  Button3.Enabled:=False;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  PlayLog:=0;
  hPlay:=SetwindowsHookEx(WH_JOURNALPLAYBACK,PlayProc,
    HInstance,0);
end;


procedure TForm1.Button2Click(Sender: TObject);
begin
  UnHookWindowsHookEx(hHook);
  hHook:=0;
  Button1.Enabled:=True;
  Button2.Enabled:=False;
  Button3.Enabled:=True;
end;

procedure TForm1.Button4Click(Sender: TObject);
var ihandle,ehandle,handle:HWND;
     s,g:string;
     sMsg:   array[0..4096]   of   Char;
     ilength,t:integer;


begin
   ihandle:=findwindow(nil,'已加载…  D:\JLJS\jldata\c080702');
 //  if ihandle>0 then
 //  begin
 //    showmessage('找到程序句柄:'+inttostr(ihandle));
  // end;

   ehandle:= findwindowex(ihandle,0,'ComboBox',nil);
   if ehandle>0  then
   begin
     showmessage('找到句柄:'+inttostr(ihandle)+'子窗口句柄:'+inttostr(ehandle));
   end;

   //  showmessage('找到句柄:'+inttostr(ihandle)+'子窗口句柄:'+inttostr(ehandle));

  //  if cHwnd>0 then PostMessage(cHwnd,WM_KEYDOWN,VK_RETURN ,0) ; //按回车键
  //SendMessage(hWnd,WM_SETTEXT,0,str)
      s:='读书铺';
      SendMessage(ehandle,WM_SETFOCUS,0,0);
      SendMessage(ehandle,WM_SETTEXT,0,Integer(PChar(s)));
      SendMessage(ehandle,WM_KEYDOWN,13,0);
      SendMessage(ehandle,WM_CHAR,13,0);
      keybd_event($13,0,0,0);
      SendMessage(ehandle,WM_KEYDOWN,VK_RETURN,0);

    //  SendMessage(ihandle,WM_char,VK_RETURN,0);    //keybd_event(13,0,0,0);
     // SendMessage(ehandle,WM_KILLFOCUS,0,0);
     ehandle:= findwindowex(ihandle,ehandle,'Edit',nil);
    if ehandle>0  then    //第二个
    begin
     showmessage('找到句柄:'+inttostr(ihandle)+'子窗口句柄:'+inttostr(ehandle));
      SendMessage(ehandle,WM_SETTEXT,0,Integer(PChar(s)));
   end;
   ehandle:= findwindowex(ihandle,ehandle,'Edit',nil); //第三个
    if ehandle>0  then
    begin
     showmessage('找到句柄:'+inttostr(ihandle)+'子窗口句柄:'+inttostr(ehandle));
     // SendMessage(ehandle,WM_SETTEXT,0,Integer(PChar(s)));
   end;
        ehandle:= findwindowex(ihandle,ehandle,'Edit',nil);    //第四个
    if ehandle>0  then
    begin
     showmessage('找到句柄:'+inttostr(ihandle)+'子窗口句柄:'+inttostr(ehandle));
      //SendMessage(ehandle,WM_GETTEXT,2048,Integer(PChar(g)));
      ilength:=SendMessage(ehandle,WM_GETTEXTLENGTH ,0,0);
      SendMessage(ehandle,WM_GETTEXT,4096,Integer(@(sMsg)));
      g:= StrPas(sMsg);
     showmessage('找到句柄:'+g);
   end;
   Private   Const   WM_CHAR   =   &H102
  Private   Const   WM_KEYDOWN   =   &H100




end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -