1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
   | procedure TForm1.Button2Click(Sender: TObject);
begin
  ShowMessage('Button2Click');
end;
 
// http://delphi.about.com/od/vclusing/a/mouseadvanced.htm
 
procedure TForm1.Button1Click(Sender: TObject);
var
  Pt: TPoint;
begin
  Application.ProcessMessages;
  {Get the point in the center of Button 2}
  Pt.x := Button2.Left + (Button2.Width div 2);
  Pt.y := Button2.Top + (Button2.Height div 2);
  {Convert Pt to screen coordinates and Mickeys}
  Pt := ClientToScreen(Pt);
  Pt.x := Round(Pt.x * (65535 / Screen.Width));
  Pt.y := Round(Pt.y * (65535 / Screen.Height));
  {Simulate the mouse move}
  Mouse_Event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_MOVE, Pt.x, Pt.y, 0, 0);
  {Simulate the left mouse button down}
  Mouse_Event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_LEFTDOWN, Pt.x, Pt.y, 0, 0);
  {Simulate the left mouse button up}
  Mouse_Event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_LEFTUP, Pt.x, Pt.y, 0, 0);
end; | 
Partager