Ejemplo n.º 1
0
        internal override void GenerateCurve()
        {
            //create the senseCurve, the start of the curve and start populating it with random values
            List <SensitivityPoint> sensCurve  = new List <SensitivityPoint>();
            SensitivityPoint        firstPoint = new SensitivityPoint(0, sensMean);

            sensCurve.Add(firstPoint);
            //Random rnd = SystemRandomSource.Default;
            var logNormal = new LogNormal(0, sigma);

            for (double timecode = curveTimestep; timecode < this.lenght; timecode += curveTimestep)
            {
                double randomSens;
                do //keep trying to create a random sens within the set min/max boundries
                {
                    randomSens = logNormal.Sample();
                } while (randomSens > sensMax || randomSens < sensMin);
                SensitivityPoint sensPoint = new SensitivityPoint(timecode, randomSens);
                sensCurve.Add(sensPoint);
            }
            SensitivityPoint finalSensPoint = new SensitivityPoint(this.lenght, 1);//Make sure the curve ends at base sens

            sensCurve.Add(finalSensPoint);
            base.sensCurve = sensCurve;
        }
Ejemplo n.º 2
0
        public void Start()
        {
            isStopped = false;
            using (Process p = Process.GetCurrentProcess()) // Raise process priotity
                p.PriorityClass = ProcessPriorityClass.High;

            IntPtr context;

            Interception.Stroke stroke = new Interception.Stroke();
            context = Interception.interception_create_context();
            int device;

            Interception.InterceptionPredicate del = Interception.interception_is_mouse;
            Interception.interception_set_filter(
                context,
                del,
                (ushort)Interception.FilterMouseState.MouseMove);
            double    magicX    = 0;
            double    magicY    = 0;
            Stopwatch stopwatch = new Stopwatch();// Start a stopwatch to be used to advance the curve

            //int sw = 0; // Rough stopwatch in ms
            while (Interception.interception_receive(context, device = Interception.interception_wait(context), ref stroke, 1) > 0)//Start listening for mouse strokes
            {
                //sw += 20; // Every cycle takes roughly 20ms so we add 20ms
                stopwatch.Start();
                if (sensitivityCurve.isFinished || isStopped)
                {
                    stopwatch.Stop();
                    break;
                }
                Interception.MouseStroke mstroke      = stroke;
                SensitivityPoint         currentPoint = sensitivityCurve.GetCurrentPoint();

                double x = mstroke.x * currentPoint.sensitivity + magicX;
                double y = mstroke.y * currentPoint.sensitivity + magicY;

                magicX = x - Math.Floor(x);
                magicY = y - Math.Floor(y);

                mstroke.x = (int)Math.Floor(x);
                mstroke.y = (int)Math.Floor(y);

                byte[] strokeBytes = Interception.getBytes(mstroke);
                Interception.interception_send(context, device, strokeBytes, 1);
                if (isPaused)
                {
                    //sw -= 20;
                    stopwatch.Reset();
                }
                if (stopwatch.ElapsedMilliseconds > sensitivityCurve.timestep * 1000) //when sw equals timestep in ms we advance the cursor
                {
                    currentSens = currentPoint.sensitivity;
                    sensitivityCurve.AdvanceCursor();
                    //sw = 0; // Reset the sw
                    stopwatch.Restart();
                }
            }
            Interception.interception_destroy_context(context);
            if (isStopped == false)
            {
                sensitivityCurve.RegenerateCurve();
                sensitivityCurve.InterpolateCurveAkima();
                Start();
            }
        }