示例#1
0
        public static void WindMouse(double xs, double ys, double xe, double ye,
                                     double gravity, double wind, double minWait, double maxWait, double maxStep, double targetArea)
        {
            double veloX = 0.0, veloY = 0.0, windX = 0.0, windY = 0.0, veloMag = 0.0, dist = 0.0, randomDist = 0.0, lastDist = 0.0, step = 0.0;
            int    lastX = 0, lastY = 0;
            double sqrt2, sqrt3, sqrt5;

            sqrt2 = Math.Sqrt(2);
            sqrt3 = Math.Sqrt(3);
            sqrt5 = Math.Sqrt(5);

            while ((dist = ScarMath.Hypotenuse(xs - xe, ys - ye)) > 1.0)
            {
                wind = Math.Min(wind, dist);

                if (dist >= targetArea)
                {
                    windX = windX / sqrt3 + (random.Next((int)Math.Round(wind) * 2 + 1) - wind) / sqrt5;
                    windY = windY / sqrt3 + (random.Next((int)Math.Round(wind) * 2 + 1) - wind) / sqrt5;
                }
                else
                {
                    windX = windX / sqrt2;
                    windY = windY / sqrt2;

                    if (maxStep < 3.0)
                    {
                        maxStep = random.Next(3) + 3.0;
                    }
                    else
                    {
                        maxStep = maxStep / sqrt5;
                    }
                }

                veloX = veloX + windX;
                veloY = veloY + windY;
                veloX = veloX + gravity * (xe - xs) / dist;
                veloY = veloY + gravity * (ye - ys) / dist;

                if (ScarMath.Hypotenuse(veloX, veloY) > maxStep)
                {
                    randomDist = maxStep / 2.0 + random.Next((int)Math.Round(maxStep) / 2);
                    veloMag    = Math.Sqrt(veloX * veloX + veloY * veloY);
                    veloX      = (veloX / veloMag) * randomDist;
                    veloY      = (veloY / veloMag) * randomDist;
                }

                lastX = (int)Math.Round(xs);
                lastY = (int)Math.Round(ys);
                xs    = xs + veloX;
                ys    = ys + veloY;

                int roundxs = (int)Math.Round(xs);
                int roundys = (int)Math.Round(ys);

                if (lastX != roundxs || lastY != roundys)
                {
                    MoveMouse(roundxs, roundys);
                }

                step = ScarMath.Hypotenuse(xs - lastX, ys - lastY);
                Thread.Sleep((int)Math.Round((maxWait - minWait) * (step / maxStep) + minWait));
                lastDist = dist;
            }

            if ((int)Math.Round(xe) != (int)Math.Round(xs) || (int)Math.Round(ye) != (int)Math.Round(ys))
            {
                MoveMouse((int)Math.Round(xe), (int)Math.Round(ye));
            }
        }
示例#2
0
        public static void MoveMouseSmoothEx(int x, int y, int minsleeptime, int maxsleeptime,
                                             int maxdistance, int gravity, int forces)
        {
            int    currX = 0, currY = 0;
            int    newX = 0, newY = 0;
            double totalDist = 0, force = 0, dist = 0, velocity = 0, angle;
            double windAngle = 0;
            double wind      = 0;
            int    loops     = 0;

            Point currentPos = GetMousePos();

            currX = currentPos.X;
            currY = currentPos.Y;

            velocity = 6;             // Start moving the mouse, mostly to keep wind from being to strong
            while ((currX != x) || (currY != y))
            {
                ++loops;
                // pow was overkill for squaring integers
                totalDist = Math.Sqrt((double)((x - currX) * (x - currX)) + ((y - currY) * (y - currY)));
                angle     = Math.Atan2((double)currY - y, (double)currX - x);

                if (maxdistance > totalDist)                  // Make sure we don't go too far.
                {
                    maxdistance = ScarMath.LRound(totalDist);
                }

                if (totalDist < (forces / 1.5))                 // Can we overcome the wind?
                {
                    MoveMouse(x, y);
                }
                else
                {
                    force     = (gravity * 100) / (totalDist * totalDist);                 // Make gravity a bit stronger
                    dist      = velocity;
                    velocity += force * loops;
                    if (dist > maxdistance)
                    {
                        dist    = maxdistance - (random.Next(maxdistance) / 2);
                        gravity = 0;                              // don't increase velocity when we reach max speed.
                    }
                    windAngle = (random.Next(360)) / 180 * 3.142; // Wheres the wind blowing?
                    wind      = random.Next(forces) * 0.5;        // How hard will it blow?

                    if (forces > totalDist)
                    {
                        forces = ScarMath.LRound(totalDist);
                    }

                    newX = ScarMath.LRound(currX - (Math.Cos(angle) * dist) + (Math.Cos(windAngle) * wind));
                    newY = ScarMath.LRound(currY - (Math.Sin(angle) * dist) + (Math.Cos(windAngle) * wind));
                    MoveMouse(newX, newY);                      // Looks like we made it.
                }
                // GetMousePos is after the sleep to ensure fluid motion in case the user
                // moves their mouse.
                Thread.Sleep(10 + minsleeptime + (random.Next(maxsleeptime - minsleeptime)));
                Point newPoint = GetMousePos();                 // Let me know if I should exit the loop
                currX = newPoint.X;
                currY = newPoint.Y;
            }
        }