/// <summary>
        /// The point of the random mouse movements is to not click the exact same coordinate every click.
        /// If there was a game, for example, and you wanted to hide the fact that you were using an auto-clicker
        /// Moving the mouse coordinates just a little bit every so often could help mask this fact.
        /// </summary>
        private void RandomlyUpdateMouseCoordinates()
        {
            if (this.run)
            {
                UpdateMouseCenterIfUserMovedMouse();

                Random rnd   = new Random();
                int    randX = this.centerMouseX + rnd.Next(1, mousePixelsToMoveFromCenter);
                int    randY = this.centerMouseY + rnd.Next(1, mousePixelsToMoveFromCenter);

                Win32.POINT p = new Win32.POINT();

                int sleepTime = rnd.Next(1000, 4500); //Sleep between 1 and 4.5 seconds..?

                Win32.ClientToScreen(this.Handle, ref p);
                Win32.SetCursorPos(randX, randY);
                System.Threading.Thread.Sleep(sleepTime);

                SetMouseCoordLabels(Cursor.Position.X.ToString(), Cursor.Position.Y.ToString());
            }
        }
Esempio n. 2
0
        public void Click(AutoAction action)
        {
            List <ClickOnPointTool.INPUT> inputs = new List <ClickOnPointTool.INPUT>();
            var chosenPoint = new Win32.POINT();

            // Move the mouse if required.
            if (action.locationType == LocationType.Fixed)
            {
                chosenPoint.x = action.x;
                chosenPoint.y = action.y;
            }
            else if (action.locationType == LocationType.Random)
            {
                chosenPoint.x = rnd.Next(65536);
                chosenPoint.y = rnd.Next(65536);
            }
            else if (action.locationType == LocationType.RandomRange)
            {
                chosenPoint.x = rnd.Next(action.x, action.x + action.width);
                chosenPoint.y = rnd.Next(action.y, action.y + action.height);
            }
            //Click Type
            for (int i = 0; i < (action.doubleClick ? 2 : 1); i++)
            {
                // Add a delay if it's a double click
                if (i == 1)
                {
                    Thread.Sleep(50);
                }

                if (action.buttonType == ButtonType.Left)
                {
                    ClickOnPointTool.INPUT inputDown = new ClickOnPointTool.INPUT
                    {
                        Type = (uint)Win32.SendInputEventType.InputMouse,
                        Data = new ClickOnPointTool.MOUSEKEYBDHARDWAREINPUT()
                        {
                            Mouse = new ClickOnPointTool.MOUSEINPUT
                            {
                                Flags = (uint)Win32.MouseEventFlags.LeftDown
                            }
                        }
                    };
                    inputs.Add(inputDown);
                    ClickOnPointTool.INPUT inputUp = new ClickOnPointTool.INPUT
                    {
                        Type = (uint)Win32.SendInputEventType.InputMouse,
                        Data = new ClickOnPointTool.MOUSEKEYBDHARDWAREINPUT()
                        {
                            Mouse = new ClickOnPointTool.MOUSEINPUT
                            {
                                Flags = (uint)Win32.MouseEventFlags.LeftUp
                            }
                        }
                    };
                    inputs.Add(inputUp);
                }

                if (action.buttonType == ButtonType.Middle)
                {
                    ClickOnPointTool.INPUT inputDown = new ClickOnPointTool.INPUT
                    {
                        Type = (uint)Win32.SendInputEventType.InputMouse,
                        Data = new ClickOnPointTool.MOUSEKEYBDHARDWAREINPUT()
                        {
                            Mouse = new ClickOnPointTool.MOUSEINPUT
                            {
                                Flags = (uint)Win32.MouseEventFlags.MiddleDown
                            }
                        }
                    };
                    inputs.Add(inputDown);
                    ClickOnPointTool.INPUT inputUp = new ClickOnPointTool.INPUT
                    {
                        Type = (uint)Win32.SendInputEventType.InputMouse,
                        Data = new ClickOnPointTool.MOUSEKEYBDHARDWAREINPUT()
                        {
                            Mouse = new ClickOnPointTool.MOUSEINPUT
                            {
                                Flags = (uint)Win32.MouseEventFlags.MiddleUp
                            }
                        }
                    };
                    inputs.Add(inputUp);
                }

                if (action.buttonType == ButtonType.Right)
                {
                    ClickOnPointTool.INPUT inputDown = new ClickOnPointTool.INPUT
                    {
                        Type = (uint)Win32.SendInputEventType.InputMouse,
                        Data = new ClickOnPointTool.MOUSEKEYBDHARDWAREINPUT()
                        {
                            Mouse = new ClickOnPointTool.MOUSEINPUT
                            {
                                Flags = (uint)Win32.MouseEventFlags.RightUp
                            }
                        }
                    };
                    inputs.Add(inputDown);
                    ClickOnPointTool.INPUT inputUp = new ClickOnPointTool.INPUT
                    {
                        Type = (uint)Win32.SendInputEventType.InputMouse,
                        Data = new ClickOnPointTool.MOUSEKEYBDHARDWAREINPUT()
                        {
                            Mouse = new ClickOnPointTool.MOUSEINPUT
                            {
                                Flags = (uint)Win32.MouseEventFlags.RightDown
                            }
                        }
                    };
                    inputs.Add(inputUp);
                }
            }

            if (inputs.Count > 0)
            {
                AutoCursor.MoveMouse(chosenPoint.x, chosenPoint.y, 0, 0);
            }

            Point lpPoint = new Point()
            {
                X = chosenPoint.x, Y = chosenPoint.y
            };

            //ClickOnPointTool.ClientToScreen(handle, ref lpPoint);

            //Another attempt, only supports left
            ClickOnPointTool.ClickOnPoint(handle, new System.Drawing.Point()
            {
                X = chosenPoint.x, Y = chosenPoint.y
            }, inputs.ToArray());
        }