频道分类

Delphi 控制鼠标按坐标点击

作者:admin 来源: 日期:2019/11/3 11:02:19 人气: 标签:

 

procedure DoIdle(XMsSec: Cardinal);
var
  ElapsedTime: Cardinal;
begin
  ElapsedTime := 0;
  while ElapsedTime < XMsSec do
  begin
    Application.ProcessMessages;
    Sleep(10);
    Inc(ElapsedTime, 10);
  end;

end;


procedure MoniClick(X, Y: Integer);
var
  LCount: Integer;
begin
  LCount := 0;
  while not SetCursorPos(X, Y) do
  begin
    Inc(LCount);
    if LCount > 100 then
      Exit;
  end;

  DoIdle(100);
  mouse_event(MOUSEEVENTF_LEFTDOWN, 0,0,0,GetMessageExtraInfo());
  DoIdle(100);
  mouse_event(MOUSEEVENTF_LEFTUP, 0,0,0,GetMessageExtraInfo());

end;