delphi 在桌面屏幕上模拟鼠标单击

procedure TFrmUnicom.Button1Click(Sender: TObject);
var
  oldPoint, newPoint: TPoint;
begin
  GetCursorPos(&oldPoint); // 保存当前鼠标位置。

  newPoint.x := 1050;
  newPoint.y := 325;
  MouseClick(newPoint); // 模拟放开鼠标左键。
  application.ProcessMessages;
  sleep(1000);
  application.ProcessMessages;
  newPoint.x := 1050;
  newPoint.y := 747;
  MouseClick(newPoint); // 模拟放开鼠标左键。
end;

procedure TFrmUnicom.MouseClick(newPoint: TPoint);
begin
  SetCursorPos(newPoint.x, newPoint.y);
  // 设置目的地位置。
  mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0);
  // 模拟按下鼠标右键。
  mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0);
  // 模拟放开鼠标右键。
  mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
  // 模拟按下鼠标左键。
  mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
end;

 

posted on 2015-11-03 14:36  lypzxy  阅读(1003)  评论(0编辑  收藏  举报