unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, ComCtrls, ToolWin, StdCtrls;<br><br>type<br> TForm1 = class(TForm)<br> ToolBar1: TToolBar;<br> ToolButton1: TToolButton;<br> ToolButton2: TToolButton;<br> Button1: TButton;<br> procedure ToolButton1Click(Sender: TObject);<br> procedure Button1Click(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure MouseMoveTo(x, y: integer);<br>var<br> p: TPoint;<br> moveX, moveY: integer;<br> i: integer;<br>begin<br><br> GetCursorPos(p);<br> while (abs(x - p.X) > 20) or (abs(y - p.y) > 20) do<br> begin<br><br> moveX := (x - p.X);<br> moveY := (y - p.y);<br> if abs(moveX) > abs(moveY) then<br> begin<br> if moveX > 0 then<br> i := 20<br> else<br> i := -20;<br> moveY := round(moveY / moveX * i + 0.5);<br> moveX := i;<br> end<br> else<br> begin<br> if moveY > 0 then<br> i := 20<br> else<br> i := -20;<br> moveX := round(moveX / moveY * i + 0.5);<br> moveY := i;<br> end;<br> mouse_event(MOUSEEVENTF_MOVE, moveX, movey, 0, 0);<br> sleep(50);<br><br> GetCursorPos(p);<br> end;<br> GetCursorPos(p);<br> while (p.x <> x) or (p.Y <> y) do<br> begin<br> moveX := 0;<br> moveY := 0;<br> if x > p.X then<br> moveX := 1;<br> if x < p.X then<br> moveX := -1;<br><br> if y > p.y then<br> movey := 1;<br> if y < p.y then<br> movey := -1;<br><br> mouse_event(MOUSEEVENTF_MOVE, moveX, movey, 0, 0);<br> GetCursorPos(p);<br> end;<br>end;<br><br>procedure MouseMoveToControl(V: TControl; WillClick: boolean);<br>var<br> p: Tpoint;<br>begin<br><br> p.X := v.Width div 2;<br> p.Y := v.Height div 2;<br> p := v.ClientToScreen(p);<br> MouseMoveTo(p.X, p.Y);<br> if WillClick then<br> begin<br> sleep(400);<br><br> mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);<br> mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);<br> end;<br><br>end;<br>procedure MouseMoveToWillClick(x, y: integer);<br>begin<br> MouseMoveTo(x, y);<br> sleep(400);<br><br> mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);<br> mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);<br><br>end;<br>procedure TForm1.ToolButton1Click(Sender: TObject);<br>begin<br> showmessage(Sender.ClassName);<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br> MouseMoveToControl (ToolButton1,true) ;<br>end;<br><br>end.<br><br>