delphi 鼠标拖动

GetWindowRect(tgph, Rect); //获得窗体大小
setcursorpos(Rect.Left + 487, Rect.Top + 274);
delay(100);
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
delay(100);
mouse_event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_MOVE, round((Rect.Left + 324) * 65535 / screen.Width), round((Rect.Top + 381) * 65535 / screen.Height), 0, 0);
delay(300);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);

最重要的是红色字部分,移动鼠标的坐标需要进行一个换算通过屏幕尺寸进行比例换算,否则移动的位置坐标永远都是错误的

原文地址:https://www.cnblogs.com/gtsup/p/7122576.html