示例#1
0
        private List<Point> MouseMoveAndClick(int x, int y)
        {
            lock (Lock)
            {
                int pointerAccuracy = 10; //assume 10 pixels is the accuracy of this particular human's point and click

                //calculate an X-Y offset to mimic the accuracy of a human
                int targetX = x + Convert.ToInt32(pointerAccuracy * targetDistribution.NextGaussian());
                int targetY = y + Convert.ToInt32(pointerAccuracy * targetDistribution.NextGaussian());

                //declare the original pointer position
                int originalX = System.Windows.Forms.Cursor.Position.X;
                int originalY = System.Windows.Forms.Cursor.Position.Y;

                //find a mid point between original and target position
                int midPointX = (x - targetX) / 2;
                int midPointY = (y - targetY) / 2;

                //Find a co-ordinate normal to the straight line between start and end point, starting at the midpoint and normally distributed
                //This is reduced by a factor of 4 to model the arc of a right handed user.
                int bezierMidPointX = Convert.ToInt32((midPointX / 4) * (midpointDistribution.NextGaussian()));
                int bezierMidPointY = Convert.ToInt32((midPointY / 4) * (midpointDistribution.NextGaussian()));

                BezierCurve bc = new BezierCurve();
                double[] input = new double[] { originalX, originalY, bezierMidPointX, bezierMidPointY, targetX, targetY };

                int numberOfDataPoints = 50;
                double[] output = new double[numberOfDataPoints];

                //co-ords are couplets of doubles hence the / 2
                bc.Bezier2D(input, numberOfDataPoints / 2, output);

                int pause = 0;

                List<System.Drawing.Point> points = new List<Point>();
                for (int count = 1; count != numberOfDataPoints - 1; count += 2)
                {
                    Point point = new System.Drawing.Point((int)output[count + 1], (int)output[count]);
                    points.Add(point);
                    System.Windows.Forms.Cursor.Position = point;

                    //we can vary when we pause between moving from point to point, but to replicate how a user's action will slow down prior to clicking:
                    //if ((count % 10) == 0)
                    pause = 89 + ((count ^ 5) / (count * 2)) * 5;

                    System.Threading.Thread.Sleep(pause);

                }

                //Use the Win32 API to send a mouse down/ mouse up events seperated by an arbitrary pause
                //mouse_event((int)(MouseEventFlags.LEFTDOWN), 0, 0, 0, 0);
                System.Threading.Thread.Sleep(50);
                //mouse_event((int)(MouseEventFlags.LEFTUP), 0, 0, 0, 0);

                return points;
            }
        }
示例#2
0
        private void CursorTracking(int toX, int toY)
        {
            Point defPnt = new Point();
            GetCursorPos(ref defPnt);

            //int targetMidPointX = toX; //(defPnt.X < toX) ? toX : defPnt.X;
            //int targetMidPointY = toY; // (defPnt.Y < toY) ? toY : defPnt.Y;//this.Location.Y + windowToClientOffsetY + btnTarget.Top + (int)Math.Floor((decimal)btnTarget.Size.Height / 2);

            //MouseMove(targetMidPointX, targetMidPointY);
            lock (Lock)
            {
                //int pointerAccuracy = 4; //assume 10 pixels is the accuracy of this particular human's point and click

                //calculate an X-Y offset to mimic the accuracy of a human
                int targetX = toX; //x;// +Convert.ToInt32(pointerAccuracy * targetDistribution.NextGaussian());
                int targetY = toY; //y;// +Convert.ToInt32(pointerAccuracy * targetDistribution.NextGaussian());

                //declare the original pointer position
                int originalX = System.Windows.Forms.Cursor.Position.X;
                int originalY = System.Windows.Forms.Cursor.Position.Y;

                //find a mid point between original and target position
                int midPointX = (defPnt.X - targetX) / 2;
                int midPointY = (defPnt.Y - targetY) / 2;

                //Find a co-ordinate normal to the straight line between start and end point, starting at the midpoint and normally distributed
                //This is reduced by a factor of 4 to model the arc of a right handed user.
                int bezierMidPointX = Convert.ToInt32(midPointX +100); // * (midpointDistribution.NextGaussian()));
                int bezierMidPointY = Convert.ToInt32(midPointY +100); // * (midpointDistribution.NextGaussian()));

                BezierCurve bc = new BezierCurve();
                double[] input = new double[] { originalX, originalY, bezierMidPointX, bezierMidPointY, targetX, targetY };

                int numberOfDataPoints = 50;
                double[] output = new double[numberOfDataPoints];

                //co-ords are couplets of doubles hence the / 2
                bc.Bezier2D(input, numberOfDataPoints / 2, output);

                int pause = 0;

                List<System.Drawing.Point> points = new List<Point>();
                for (int count = 1; count != numberOfDataPoints - 1; count += 2)
                {
                    Point point = new System.Drawing.Point((int)output[count + 1], (int)output[count]);
                    points.Add(point);
                    System.Windows.Forms.Cursor.Position = point;

                    //we can vary when we pause between moving from point to point, but to replicate how a user's action will slow down prior to clicking:
                    //if ((count % 10) == 0)
                    pause = 74 + ((count ^ 5) / (count * 2)) * 5;

                    System.Threading.Thread.Sleep(pause);

                }

                //Use the Win32 API to send a mouse down/ mouse up events seperated by an arbitrary pause
                //mouse_event((int)(MouseEventFlags.LEFTDOWN), 0, 0, 0, 0);
                System.Threading.Thread.Sleep(15);
                //mouse_event((int)(MouseEventFlags.LEFTUP), 0, 0, 0, 0);
            }
        }