Exemplo n.º 1
0
        public MouseCommand _Click(MouseCommButton button, int count, MousePoint position)
        {
            MouseEventFlags clk;

            if (button == MouseCommButton.Middle)
            {
                clk = MouseEventFlags.MiddleDown | MouseEventFlags.MiddleUp;
            }
            else if (button == MouseCommButton.Right)
            {
                clk = MouseEventFlags.RightDown | MouseEventFlags.RightUp;
            }
            else
            {
                clk = MouseEventFlags.LeftDown | MouseEventFlags.LeftUp;
            }

            MouseCommand m = Click((int)clk, count, position);

            if (count == 1)
            {
                MouseActionEventCall?.Invoke(MouseActionEvent.Clicked, position);
            }
            else if (count == 2)
            {
                MouseActionEventCall?.Invoke(MouseActionEvent.DblClicked, position);
            }
            else
            {
                MouseActionEventCall?.Invoke(MouseActionEvent.MultiClicked, position);
            }
            return(m);
        }
Exemplo n.º 2
0
        public MouseCommand _Drag(MousePoint position1, MousePoint position2, MouseCommButton button = MouseCommButton.Left, int speed = 50)
        {
            MouseEventFlags up;

            if (button == MouseCommButton.Middle)
            {
                up = MouseEventFlags.MiddleUp;
            }
            else if (button == MouseCommButton.Right)
            {
                up = MouseEventFlags.RightUp;
            }
            else
            {
                up = MouseEventFlags.LeftUp;
            }

            mouse_event((int)button, position1.X, position1.Y, 0, 0);
            System.Threading.Tasks.Task.Delay(1).Wait();

            if (speed != 0)
            {
                decimal x1    = (decimal)position1.X;
                decimal y1    = (decimal)position1.Y;
                decimal x2    = (decimal)position2.X;
                decimal y2    = (decimal)position2.Y;
                decimal xDif  = x1 - x2;
                decimal yDif  = y1 - y2;
                decimal avg   = (xDif + yDif) / 2;
                decimal steps = (avg / speed);


                //double the steps for smoother transition
                decimal xStep = ((position1.X - position2.X) / steps) / 2; if (position1.X > position2.X)
                {
                    xStep = -xStep;
                }
                decimal yStep = ((position1.Y - position2.Y) / steps) / 2; if (position1.Y > position2.Y)
                {
                    yStep = -yStep;
                }
                if (steps < 0)
                {
                    steps = 1;
                }
                for (int i = 0; i <= steps * 2; i++)
                {
                    SetCursorPosition((int)x1, (int)y1); x1 += xStep; y1 += yStep; System.Threading.Tasks.Task.Delay(1).Wait();
                }
            }
            SetCursorPosition(position2);
            System.Threading.Tasks.Task.Delay(1).Wait();
            mouse_event((int)up, position2.X, position2.Y, 0, 0);

            MouseActionEventCall?.Invoke(MouseActionEvent.Dragged, position2);
            return(this);
        }
Exemplo n.º 3
0
        public MouseCommand _MoveCursorPosition(MousePoint position2, int speed = 50)
        {
            MousePoint position1 = CurrentMousePoint;

            if (speed != 0)
            {
                decimal x1    = (decimal)position1.X;
                decimal y1    = (decimal)position1.Y;
                decimal x2    = (decimal)position2.X;
                decimal y2    = (decimal)position2.Y;
                decimal xDif  = x1 - x2;
                decimal yDif  = y1 - y2;
                decimal avg   = (xDif + yDif) / 2;
                decimal steps = (avg / speed);


                //double the steps for smoother transition
                decimal xStep = ((position1.X - position2.X) / steps) / 2; if (position1.X > position2.X)
                {
                    xStep = -xStep;
                }
                decimal yStep = ((position1.Y - position2.Y) / steps) / 2; if (position1.Y > position2.Y)
                {
                    yStep = -yStep;
                }
                if (steps < 0)
                {
                    steps = 1;
                }
                for (int i = 0; i <= steps * 2; i++)
                {
                    SetCursorPosition((int)x1, (int)y1); x1 += xStep; y1 += yStep; System.Threading.Tasks.Task.Delay(1).Wait();
                }
            }
            SetCursorPosition(position2);
            MouseActionEventCall?.Invoke(MouseActionEvent.Moved, position2);
            return(this);
        }