我有一个外部窗口我发送鼠标并拖动到。出于某种原因,它不会拖动它。任何帮助深表感谢。
public void clickAndDrag(Point pointA, Point pointB)
{
Point tmp = Cursor.Position;
mouse_event((int)(MouseEventFlags.LEFTUP), 0, 0, 0, 0);
Cursor.Position = ConvertToScreenPixel(pointA);
System.Threading.Thread.Sleep(1000);
mouse_event((int)(MouseEventFlags.LEFTDOWN), 0, 0, 0, 0);
Cursor.Position = ConvertToScreenPixel(pointB);
System.Threading.Thread.Sleep(1000);
mouse_event((int)(MouseEventFlags.LEFTUP), 0, 0, 0, 0);
Cursor.Position = tmp;
}
答案 0 :(得分:-1)
我明白了。我猜你需要慢慢移动鼠标。但这点击并向左拖动了一点。这是完全垃圾,但我太累了,不能尝试重构它。
public void clickAndDrag(Point pointA)
{
Point tmp = Cursor.Position;
pointA.X = pointA.X + 20;
pointA.Y = pointA.Y + 20;
mouse_event((int)(MouseEventFlags.LEFTUP), 0, 0, 0, 0);
Cursor.Position = ConvertToScreenPixel(pointA);
System.Threading.Thread.Sleep(1000);
mouse_event((int)(MouseEventFlags.LEFTDOWN), 0, 0, 0, 0);
for (var i = 0; i < 10; i++)
{
pointA.X = pointA.X - 10;
Cursor.Position = ConvertToScreenPixel(pointA);
System.Threading.Thread.Sleep(200);
mouse_event((int)(MouseEventFlags.MOVE), 0, 0, 0, 0);
}
mouse_event((int)(MouseEventFlags.LEFTUP), 0, 0, 0, 0);
Cursor.Position = tmp;
}