Attempting to Simulate Mouse Click / Drag

后端 未结 3 1260
既然无缘
既然无缘 2021-01-12 16:33

So I\'m trying to simulate the left mouse click and the left mouse release to do some automated dragging and dropping.

It\'s currently in a C# Winforms (Yes, winform

3条回答
  •  一个人的身影
    2021-01-12 17:22

    The Easiest answer was infact to use a bool and just check to see what's going on.

    I started it on a new thread so it didn't break everything else.

    Idealy you'd tidy this up a little bit.

        public static void Grab(int xPos, int yPos)
        {
            _dragging = true;
    
            Cursor.Position = new Point(xPos, yPos + offSet);
            mouse_event(leftDown, (uint) xPos, (uint) yPos, 0, 0);
    
            var t = new Thread(CheckMouseStatus);
            t.Start();
        }
        public static void Release(int xPos, int yPos)
        {
            _dragging = false;
            Cursor.Position = new Point(xPos, yPos + offSet);
            mouse_event(leftUp, (uint) xPos, (uint) yPos, 0, 0);
        }
    
        private static void CheckMouseStatus()
        {
            do
            {
                Cursor.Position = new Point(KinectSettings.movement.HandX, KinectSettings.movement.HandY + offSet);
            } 
            while (_dragging);
        }
    

提交回复
热议问题