private static void UpdatePast(Input i) { m_LastElapsed = m_Stopwatch.ElapsedMilliseconds; // Get mouse data Interception.MouseStroke strk = i.Stroke; int mX = strk.x; int mY = strk.y; // Convert data to joystick values int convX = mX * Config.m_Config.m_Sens; int convY = -(mY * Config.m_Config.m_Sens); int offset = Config.m_Config.m_AntiAccelerationOffset; convX += (convX > 0) ? offset : ((convX < 0) ? -offset : 0); convY += (convY > 0) ? offset : ((convY < 0) ? -offset : 0); convX = (convX < short.MinValue) ? short.MinValue : ((convX > short.MaxValue) ? short.MaxValue : convX); convY = (convY < short.MinValue) ? short.MinValue : ((convY > short.MaxValue) ? short.MaxValue : convY); Pair p = new Pair(convX, convY); m_Past.Add(p); while (m_Past.Count > m_SampleCount) { m_Past.RemoveAt(0); } }
public Input(Interception.MouseStroke s) { m_InputType = InputType.Mouse; Stroke = s; if ((s.state & (ushort)Interception.MouseState.LeftDown) > 0 || (s.state & (ushort)Interception.MouseState.LeftUp) > 0) { Code.Add((ushort)MouseInput.LeftMouse); InputState inputstate = (s.state == ((ushort)Interception.MouseState.LeftDown) ? InputState.Down : InputState.Up); m_InputState.Add(inputstate); Mouse_KeyState = (inputstate == InputState.Down) ? Mouse_KeyState | (ushort)MouseInput.LeftMouse : Mouse_KeyState & ~(ushort)MouseInput.LeftMouse; IsChanged.Add(true); } if ((s.state & (ushort)Interception.MouseState.RightDown) > 0 || (s.state & (ushort)Interception.MouseState.RightUp) > 0) { Code.Add((ushort)MouseInput.RightMouse); InputState inputstate = (s.state == ((ushort)Interception.MouseState.RightDown) ? InputState.Down : InputState.Up); m_InputState.Add(inputstate); Mouse_KeyState = (inputstate == InputState.Down) ? Mouse_KeyState | (ushort)MouseInput.RightMouse : Mouse_KeyState & ~(ushort)MouseInput.RightMouse; IsChanged.Add(true); } if ((s.state & (ushort)Interception.MouseState.MiddleDown) > 0 || (s.state & (ushort)Interception.MouseState.MiddleUp) > 0) { Code.Add((ushort)MouseInput.MiddleMouse); InputState inputstate = (s.state == ((ushort)Interception.MouseState.MiddleDown) ? InputState.Down : InputState.Up); m_InputState.Add(inputstate); Mouse_KeyState = (inputstate == InputState.Down) ? Mouse_KeyState | (ushort)MouseInput.MiddleMouse : Mouse_KeyState & ~(ushort)MouseInput.MiddleMouse; IsChanged.Add(true); } if ((s.state & (ushort)Interception.MouseState.Button4Down) > 0 || (s.state & (ushort)Interception.MouseState.Button4Up) > 0) { Code.Add((ushort)MouseInput.Button4); InputState inputstate = (s.state == ((ushort)Interception.MouseState.Button4Down) ? InputState.Down : InputState.Up); m_InputState.Add(inputstate); Mouse_KeyState = (inputstate == InputState.Down) ? Mouse_KeyState | (ushort)MouseInput.Button4 : Mouse_KeyState & ~(ushort)MouseInput.Button4; IsChanged.Add(true); } if ((s.state & (ushort)Interception.MouseState.Button5Down) > 0 || (s.state & (ushort)Interception.MouseState.Button5Up) > 0) { Code.Add((ushort)MouseInput.Button5); InputState inputstate = (s.state == ((ushort)Interception.MouseState.Button5Down) ? InputState.Down : InputState.Up); m_InputState.Add(inputstate); Mouse_KeyState = (inputstate == InputState.Down) ? Mouse_KeyState | (ushort)MouseInput.Button5 : Mouse_KeyState & ~(ushort)MouseInput.Button5; IsChanged.Add(true); } if ((s.state & (ushort)Interception.MouseState.MouseWheel) > 0 || (s.state & (ushort)Interception.MouseState.MouseHWheel) > 0) { if (s.rolling > 0) { Code.Add((ushort)MouseInput.WheelUp); } else { Code.Add((ushort)MouseInput.WheelDown); } m_InputState.Add(InputState.Impulse); IsChanged.Add(true); } if (s.x != 0 || s.y != 0) { Code.Add((ushort)MouseInput.Move); IsChanged.Add(true); } }
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); }
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(); } }