[Delphi] 纯文本查看 复制代码
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
Vcl.StdCtrls, System.Actions, Vcl.ActnList;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Edit1: TEdit;
ActionList1: TActionList;
SendPress: TAction;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure SendPressExecute(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses
Tlhelp32;
function TForm1.Test2(s: string): string;
var
hCurrentWindow: hWnd;
szText: array[0..254] of char;
h: Integer;
lpCaption: array[Byte] of Char;
begin
hCurrentWindow := GetWindow(0, GW_HWNDFIRST); //获取第一个窗口的句柄
while hCurrentWindow <> 0 do
begin //获取窗口的名称
if GetWindowText(hCurrentWindow, szText, 255) > 0 then
begin
//ListBox1.Items.Add(StrPas(szText)); //获取下一窗口的句柄
if (POS('- x32dbg', StrPas(szText)) > 0) or (POS('- x64dbg', StrPas(szText)) > 0) then
begin
//ShowMessage(StrPas(szText));
h := FindWindow(nil, PWideChar(StrPas(szText)));
//ShowMessage(IntToStr(h));
IntToStr(GetWindowText(h, lpCaption, 255));
//ShowMessage(lpCaption);
SetForegroundWindow(FindWindow(nil, PWideChar(StrPas(szText))));
Sleep(500);
SetCursorPos(850, 350);
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
Sleep(1000);
keybd_event(VK_Control, MapVirtualKey(VK_Control, 0), 0, 0); //按下Ctrl键
keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), 0, 0); //按下回车键
keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), KEYEVENTF_KEYUP, 0); //弹起回车键
keybd_event(VK_Control, MapVirtualKey(VK_Control, 0), KEYEVENTF_KEYUP, 0); //放开Ctrl键
Sleep(1000);
keybd_event(VK_Control, MapVirtualKey(VK_Control, 0), 0, 0); //按下Ctrl键
keybd_event(ord('V'), MapVirtualKey(ord('V'), 0), 0, 0); //按下v键
keybd_event(VK_Control, MapVirtualKey(VK_Control, 0), KEYEVENTF_KEYUP, 0); //放开Ctrl键
keybd_event(ord('V'), MapVirtualKey(ord('V'), 0), KEYEVENTF_KEYUP, 0); //放开v键
end;
end;
hCurrentWindow := GetWindow(hCurrentWindow, GW_HWNDNEXT);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
hCurrentWindow: hWnd;
szText: array[0..254] of char;
h: Integer;
lpCaption: array[Byte] of Char;
begin
hCurrentWindow := GetWindow(0, GW_HWNDFIRST); //获取第一个窗口的句柄
while hCurrentWindow <> 0 do
begin //获取窗口的名称
if GetWindowText(hCurrentWindow, szText, 255) > 0 then
begin
//ListBox1.Items.Add(StrPas(szText)); //获取下一窗口的句柄
if (POS('- x32dbg', StrPas(szText)) > 0) or (POS('- x64dbg', StrPas(szText)) > 0) then
begin
//ShowMessage(StrPas(szText));
h := FindWindow(nil, PWideChar(StrPas(szText)));
//ShowMessage(IntToStr(h));
IntToStr(GetWindowText(h, lpCaption, 255));
//ShowMessage(lpCaption);
SetForegroundWindow(FindWindow(nil, PWideChar(StrPas(szText))));
Sleep(500);
SetCursorPos(850, 350);
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
Sleep(1000);
keybd_event(VK_Control, MapVirtualKey(VK_Control, 0), 0, 0); //按下Ctrl键
keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), 0, 0); //按下回车键
keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), KEYEVENTF_KEYUP, 0); //弹起回车键
keybd_event(VK_Control, MapVirtualKey(VK_Control, 0), KEYEVENTF_KEYUP, 0); //放开Ctrl键
Sleep(1000);
keybd_event(VK_Control, MapVirtualKey(VK_Control, 0), 0, 0); //按下Ctrl键
keybd_event(ord('V'), MapVirtualKey(ord('V'), 0), 0, 0); //按下v键
keybd_event(VK_Control, MapVirtualKey(VK_Control, 0), KEYEVENTF_KEYUP, 0); //放开Ctrl键
keybd_event(ord('V'), MapVirtualKey(ord('V'), 0), KEYEVENTF_KEYUP, 0); //放开v键
end;
end;
hCurrentWindow := GetWindow(hCurrentWindow, GW_HWNDNEXT);
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
SendPressExecute(SendPress);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
Test2(Edit1.Text);
end;
procedure TForm1.SendPressExecute(Sender: TObject);
var
hCurrentWindow: hWnd;
szText: array[0..254] of char;
h: Integer;
lpCaption: array[Byte] of Char;
begin
hCurrentWindow := GetWindow(Handle, GW_HWNDFIRST); //获取第一个窗口的句柄
while hCurrentWindow <> 0 do
begin //获取窗口的名称
if GetWindowText(hCurrentWindow, szText, 255) > 0 then
begin
//ListBox1.Items.Add(StrPas(szText)); //获取下一窗口的句柄
if (POS('- x32dbg', StrPas(szText)) > 0) or (POS('- x64dbg', StrPas(szText)) > 0) then
begin
//ShowMessage(StrPas(szText));
h := FindWindow(nil, PWideChar(StrPas(szText)));
//ShowMessage(IntToStr(h));
IntToStr(GetWindowText(h, lpCaption, 255));
//ShowMessage(lpCaption);
SetForegroundWindow(FindWindow(nil, PWideChar(StrPas(szText))));
Sleep(500);
SetCursorPos(850, 350);
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
Sleep(1000);
keybd_event(VK_Control, MapVirtualKey(VK_Control, 0), 0, 0); //按下Ctrl键
keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), 0, 0); //按下回车键
keybd_event(VK_RETURN, MapVirtualKey(VK_RETURN, 0), KEYEVENTF_KEYUP, 0); //弹起回车键
keybd_event(VK_Control, MapVirtualKey(VK_Control, 0), KEYEVENTF_KEYUP, 0); //放开Ctrl键
Sleep(1000);
keybd_event(VK_Control, MapVirtualKey(VK_Control, 0), 0, 0); //按下Ctrl键
keybd_event(ord('V'), MapVirtualKey(ord('V'), 0), 0, 0); //按下v键
keybd_event(VK_Control, MapVirtualKey(VK_Control, 0), KEYEVENTF_KEYUP, 0); //放开Ctrl键
keybd_event(ord('V'), MapVirtualKey(ord('V'), 0), KEYEVENTF_KEYUP, 0); //放开v键
end;
end;
hCurrentWindow := GetWindow(hCurrentWindow, GW_HWNDNEXT);
end;
end;
end.