/// <summary> /// Turns on / off filtering of devices /// Any filtered device will be blocked if the provider crashes /// Also controls which devices are filtered when filtering is on /// </summary> /// <param name="state">Set to true to turn filtering on</param> private void SetFilterState(bool state) { if (state && !_filterState) { HelperFunctions.Log("Enabling Interception filter"); ManagedWrapper.SetFilter(_deviceContext, IsMonitoredKeyboard, ManagedWrapper.Filter.All); ManagedWrapper.SetFilter(_deviceContext, IsMonitoredMouse, ManagedWrapper.Filter.All); _filterState = true; } else if (!state && _filterState) { HelperFunctions.Log("Disabling Interception filter"); ManagedWrapper.SetFilter(_deviceContext, IsMonitoredKeyboard, ManagedWrapper.Filter.None); ManagedWrapper.SetFilter(_deviceContext, IsMonitoredMouse, ManagedWrapper.Filter.None); _filterState = false; } }
public void EchoInput() { Console.WriteLine("Echo mode activated. Press Ctrl-C to exit."); Console.WriteLine("code\tstate\tname"); ManagedWrapper.SetFilter(context, ManagedWrapper.IsKeyboard, ManagedWrapper.Filter.All); try { while (true) { int device; var stroke = new ManagedWrapper.Stroke(); if (ManagedWrapper.Receive(context, device = ManagedWrapper.WaitWithTimeout(context, 5), ref stroke, 1) > 0) { if (ManagedWrapper.IsKeyboard(device) > 0) { int scancode = stroke.key.code; if ((stroke.key.state & 2) != 0) { scancode += 256; } Console.WriteLine($"{stroke.key.code}\t" + $"{(ManagedWrapper.KeyState) stroke.key.state}\t" + $"{KeyNameHelper.GetNameFromScanCode(scancode)}"); ManagedWrapper.Send(context, device, ref stroke, 1); } } } } catch (Exception e) { Console.Error.WriteLine(e); } }