下面一段程序模拟鼠标为什么不行?

stgsd stgsd 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
明明已经向目标窗口发了鼠标消息,为什么就没有效果呢?

unit Unit1;

interface

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

type
TForm1 = class(TForm)
ComboBox1: TComboBox;
Button1: TButton;
Timer1: TTimer;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure ComboBox1Click(Sender: TObject);
private
{ Private declarations }
procedure myhotkey(var msg: Twmhotkey);message wm_hotkey;
public
{ Public declarations }
end;

var
Form1: TForm1;
hh:hwnd;
hhh:integer;
p:tpoint;
implementation

{$R *.dfm}
//列举所有窗口
procedure TForm1.Button1Click(Sender: TObject);
var
h:hwnd;
r:array[0..254]of char;
begin
if combobox1.Items.Count>0 then combobox1.Items.Clear;
h:=getwindow(handle,gw_hwndfirst);
while h<>0 do
begin
if getwindowtext(h,@r,255)>0 then
form1.ComboBox1.Items.Add(strpas(@r)) ;
h:=getwindow(h,gw_hwndnext);
end;
end;

procedure TForm1.FormActivate(Sender: TObject);
begin
hhh:=GlobalAddAtom('hotkey');
RegisterHotKey(handle, hhh, 0, vk_home);
end;
//按‘home’选鼠标将要点击的地方
procedure Tform1.myhotkey(var msg: Twmhotkey);
begin
getcursorpos(p);
//
end;
//在下面模拟鼠标,timer为5秒
procedure TForm1.Timer1Timer(Sender: TObject);
begin
sendmessage(hh,$203,p.X,p.Y);
//sendmessage(hh,wm_lbuttondown,p.x,p.y);
sleep(200);
//sendmessage(hh,wm_lbuttonup,p.x,p.y);
end;
//控制模拟开关
procedure TForm1.Button2Click(Sender: TObject);
begin
if timer1.Enabled=false then
timer1.Enabled:=true else
timer1.Enabled:=false;
end;
//选定一个窗口
procedure TForm1.ComboBox1Click(Sender: TObject);
begin
hh:=findwindow(nil,pchar(combobox1.Items[combobox1.itemindex]));
end;

end.
...全文

相关推荐

评论 9
收藏 已收藏
分享
返回顶部
stgsd
Windows SDK/API 1,184 成员 22,326 内容