参考 http://www.delphibbs.com/delphibbs/dispq.asp?lid=1395801
以下是我的答案:
这一问题在 win98 下已圆满解决!!!
procedure MoveToTarget(pTarget:TPoint);
var
p:TPoint;
i,n,dx,dy,mx,my,sx,sy:integer;
begin
n:=20;
windows.getcursorpos(p);
dx:=(pTarget.x-p.x) div 2;
dy:=(pTarget.y-p.y) div 2;
if dx>0 then sx:=1 else sx:=-1;
if dy>0 then sy:=1 else sy:=-1;
dx:=abs(dx);
dy:=abs(dy);
mx:=dx mod n;
dx:=dx div n;
my:=dy mod n;
dy:=dy div n;
mx:=mx*sx;
dx:=dx*sx;
my:=my*sy;
dy:=dy*sy;
mouse_event(MOUSEEVENTF_MOVE,mx,my,0,0);
for i:=1 to n do
begin
sleep(100);
mouse_event(MOUSEEVENTF_MOVE,dx,dy,0,0);
end;
end;
//以下程序在 win98 下测试成功,分辨率为 800X600
//假设“开始”菜单的中心位置屏幕坐标为 (25,586)
//假设“我的电脑”图标的中心位置屏幕坐标为 (35,25)
// 移向开始菜单,并将它点开
procedure TForm1.Button1Click(Sender: TObject);
begin
MoveToTarget(point(25,586)); //移向开始菜单
sleep(500);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0); //点击
mouse_event(MOUSEEVENTF_LEFTUP ,0,0,0,0);
end;
// 移向我的电脑,并将它打开
procedure TForm1.Button2Click(Sender: TObject);
begin
keybd_event(vk_lwin,0,0,0);
keybd_event(68,0,0,0);
keybd_event(68,0,KEYEVENTF_KEYUP,0);
keybd_event(vk_lwin,0,KEYEVENTF_KEYUP,0);
MoveToTarget(point(35,25)); //移向“我的电脑”
sleep(500);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0); //点击
mouse_event(MOUSEEVENTF_LEFTUP ,0,0,0,0);
sleep(10);
mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0); //形成双击
mouse_event(MOUSEEVENTF_LEFTUP ,0,0,0,0);
end;