Ejemplo n.º 1
0
        public void StartListener()
        {
            isStopped = false;
            IntPtr context;

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

            Interception.InterceptionPredicate del = Interception.interception_is_keyboard;
            Interception.interception_set_filter(
                context,
                del,
                (ushort)Interception.FilterKeyState.KeyDown);
            while (!isStopped) //Start listening for keyboard strokes
            {
                Interception.interception_receive(context, device = Interception.interception_wait(context), ref stroke, 1);
                Interception.KeyStroke kstroke = stroke;
                byte[] strokeBytes             = Interception.getBytes(kstroke);
                Interception.interception_send(context, device, strokeBytes, 1);
                if (kstroke.code == pauseKey)
                {
                    OnPauseKeyPressed(); //If the registered key matches the pause key invoke the pausekey event
                }
                if (kstroke.code == stopKey)
                {
                    OnStopKeyPressed();
                }
            }
            Interception.interception_destroy_context(context);
        }
Ejemplo n.º 2
0
        private int InterceptKey()
        {
            int    keyCode;
            IntPtr context;

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

            Interception.InterceptionPredicate del = Interception.interception_is_keyboard;
            Interception.interception_set_filter(
                context,
                del,
                (ushort)Interception.FilterKeyState.KeyDown);
            Interception.interception_receive(context, device = Interception.interception_wait(context), ref stroke, 1);
            Interception.KeyStroke kstroke = stroke;
            keyCode = kstroke.code;
            byte[] strokeBytes = Interception.getBytes(kstroke);
            Interception.interception_send(context, device, strokeBytes, 1);
            Interception.interception_destroy_context(context);
            return(keyCode);
        }
Ejemplo n.º 3
0
        private void Intercept()
        {
            IntPtr context = Interception.interception_create_context();

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

            // Check for keyboard changes
            Interception.InterceptionPredicate interception_is_keyboard = Interception.interception_is_keyboard;
            Interception.interception_set_filter(
                context,
                interception_is_keyboard,
                ((ushort)Interception.FilterKeyState.KeyDown |
                 (ushort)Interception.FilterKeyState.KeyUp));

            // Check for mouse changes
            Interception.InterceptionPredicate interception_is_mouse = Interception.interception_is_mouse;
            Interception.interception_set_filter(
                context,
                interception_is_mouse,
                (ushort)Interception.FilterMouseState.All);

            while (Interception.interception_receive(context, device = Interception.interception_wait(context), ref stroke, 1) > 0)
            {
                byte[] strokeBytes = Interception.getBytes(stroke);
                if (Interception.interception_is_keyboard(device) != 0)
                {
                    Interception.KeyStroke kstroke = stroke;

                    if (kstroke.code == (ushort)Input.DIK.LWin || kstroke.code == (ushort)Input.DIK.RWin)
                    {
                        Interception.interception_send(context, device, strokeBytes, 1);
                        continue;
                    }

                    Input i = new Input(kstroke);

                    if (i.m_InputType == Input.InputType.Keyboard && Config.m_Config.m_KillSwitch == (Input.DIK)i.Code[0] && i.m_InputState[0] == Input.InputState.Down)
                    {
                        if (XMode.IsActive())
                        {
                            XMode.Stop(false);
                        }
                        else
                        {
                            XMode.Start();
                        }

                        continue;
                    }

                    Input.InputAction act = i.CallKeyListeners();

                    if ((act & Input.InputAction.Block) == 0)
                    {
                        Interception.interception_send(context, device, strokeBytes, 1);
                    }
                }
                else if (Interception.interception_is_mouse(device) != 0)
                {
                    Interception.MouseStroke kstroke = stroke;
                    Input i = new Input(kstroke);

                    Input.InputAction act = i.CallKeyListeners();

                    if ((act & Input.InputAction.Block) == 0)
                    {
                        Interception.interception_send(context, device, strokeBytes, 1);
                    }
                }
            }

            Interception.interception_destroy_context(context);
        }
Ejemplo n.º 4
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();
            }
        }