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); }
public static void KeyUp(DeviceID deviceID, params Key[] keys) { foreach (Key key in keys) { Interception.Stroke stroke = new Interception.Stroke(); stroke.Key = ToKeyStroke(key, false); Interception.Send(context, deviceID, ref stroke, 1); } }
public static void Update() { // Повторяем цикл, пока есть необработанные нажатия while (true) { DeviceID deviceID = Interception.WaitWithTimeout(context, 0); if (deviceID == 0) { break; } currentDeviceID = deviceID; Interception.Stroke stroke = new Interception.Stroke(); while (Interception.Receive(context, deviceID, ref stroke, 1) > 0) { Key key = ToKey(stroke.Key); if (showKeys) { Console.WriteLine("Key: {0}; Scancode: 0x{1:X2}; State: {2}", key, stroke.Key.Code, stroke.Key.State); } bool processed; KeyList deviceDownedKeys = GetOrCreateKeyList(downedKeys, deviceID); if (stroke.Key.State.IsKeyDown()) { if (!deviceDownedKeys.Contains(key)) { deviceDownedKeys.Add(key); processed = OnKeyDown(key, false); } else { processed = OnKeyDown(key, true); } } else { deviceDownedKeys.Remove(key); processed = OnKeyUp(key); } if (!processed) { Interception.Send(context, deviceID, ref stroke, 1); } } } }
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); }
public Input(Interception.KeyStroke s) { m_InputType = InputType.Keyboard; Stroke = s; Code.Add(s.code); if (s.state == (ushort)Interception.KeyState.KeyDown) { m_InputState.Add(InputState.Down); IsChanged.Add(DIK_KeyState[s.code] == false); DIK_KeyState[s.code] = true; } else if (s.state == (ushort)Interception.KeyState.KeyUp) { m_InputState.Add(InputState.Up); IsChanged.Add(DIK_KeyState[s.code] == true); DIK_KeyState[s.code] = false; } else { m_InputState.Add(InputState.Invalid); } }
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 static void Run() { var input = new List <Interception.KeyStroke>(6); var stroke = new Interception.Stroke(); var context = Interception.CreateContext(); Interception.SetFilter(context, Interception.IsKeyboard, Interception.Filter.All); try { while (true) { var device = Interception.Wait(context); if (Interception.Receive(context, device, ref stroke, 1) <= 0) { break; } if (device == 1) { input.Add(stroke.key); while (input.Count > 0) { var match = FindMatch(input); if (match == null) { stroke.key = input[0]; Interception.Send(context, 1, ref stroke, 1); input.RemoveAt(0); continue; } else { if (match.Length > 0) { for (var i = 0; i < match.Length; i++) { stroke.key = match[i]; Interception.Send(context, 1, ref stroke, 1); } input.Clear(); } break; } } } else { var key = stroke.key; for (var i = 0; i < input.Count; i++) { stroke.key = input[i]; Interception.Send(context, 1, ref stroke, 1); } input.Clear(); stroke.key = key; Interception.Send(context, device, ref stroke, 1); } } } catch (ThreadAbortException) { } finally { Interception.DestroyContext(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(); } }