简体   繁体   English

鼠标单击并拖动不起作用

[英]mouse click and drag not working

I have a external window I am sending a mouse click and drag to.我有一个外部窗口,我正在发送鼠标单击并拖动到该窗口。 For some reason it isn't dragging it.出于某种原因,它没有拖动它。 Any help is much appreciated.任何帮助深表感谢。

        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;
    }

I figured it out.我想到了。 You need to slowly move the mouse I guess.我猜你需要慢慢移动鼠标。 But this worked to click and drag to the left a bit.但这有助于单击并向左拖动一点。 It is total garbage but I am too tired to try to refactor it.这完全是垃圾,但我太累了,无法尝试重构它。

        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;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM