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); }
static Key ToKey(Interception.KeyStroke keyStroke) { ushort result = (ushort)keyStroke.Code; if ((keyStroke.State & Interception.KeyState.E0) != 0) { result += 0x100; } return((Key)result); }
private Input.InputAction OnKillSwitchKeyChanged(Input key) { if (key.m_InputType == Input.InputType.Keyboard) { Interception.KeyStroke ks = key.Stroke; Config.m_Config.m_KillSwitch = (Input.DIK)(ks.code); Config.m_Config.Save(); Invoke(new Action(() => KillSwitchTextBox.Text = Config.m_Config.m_KillSwitch.ToString())); return(Input.InputAction.Stop); } else { return(Input.InputAction.Continue); } }
static Interception.KeyStroke ToKeyStroke(Key key, bool down) { Interception.KeyStroke result = new Interception.KeyStroke(); if (!down) { result.State = Interception.KeyState.Up; } ushort code = (ushort)key; if (code >= 0x100) { code -= 0x100; result.State |= Interception.KeyState.E0; } result.Code = code; return(result); }
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); } }
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); }
static bool Equals(Interception.KeyStroke a, Interception.KeyStroke b) { return(a.code == b.code && a.state == b.state); }