private void ClickerInputEventLoop() { // load the list of device strings to test if (!File.Exists(DEVICES_LIST_FILE)) { // write defaults string[] createText = { "HID\\VID_046D&PID_C540" }; File.WriteAllLines(DEVICES_LIST_FILE, createText); } string[] deviceStringListToTest = File.ReadAllLines(DEVICES_LIST_FILE); // initialize all available 'clicker tagets' Type[] typelist = GetClassesInNamespace(Assembly.GetExecutingAssembly(), "ClickerFixer.ClickerTargets"); for (int i = 0; i < typelist.Length; i++) { _targets.Add((IClickerTarget)Activator.CreateInstance(typelist[i])); } // initialize Interception driver try { _inteceptionContext = InterceptionDriver.CreateContext(); } catch (DllNotFoundException e) { MessageBox.Show($"Failed to load Interception. Please copy interception.dll into {System.Environment.CurrentDirectory}\n\n" + e.Message); Application.Exit(); return; } catch (Exception e) { MessageBox.Show("Failed to load Interception (interception.dll). Ensure driver installed, and you rebooted after installation.\n" + e.Message); Application.Exit(); return; } if (_inteceptionContext == IntPtr.Zero) { MessageBox.Show("Failed to load Interception (interception.dll). Ensure driver installed, and you rebooted after installation."); Application.Exit(); return; } InterceptionDriver.SetFilter(_inteceptionContext, InterceptionDriver.IsKeyboard, (Int32)KeyboardFilterMode); Stroke stroke = new Stroke(); CancellationToken token = _cancelSource.Token; while (!token.IsCancellationRequested && InterceptionDriver.Receive(_inteceptionContext, deviceId = InterceptionDriver.Wait(_inteceptionContext), ref stroke, 1) > 0) { bool isHandled = false; string handledByClientName = null; if (InterceptionDriver.IsKeyboard(deviceId) > 0 && stroke.Key.State == KeyState.E0) { Console.WriteLine($"{InterceptionDriver.GetHardwareStr(_inteceptionContext, deviceId)} Code={stroke.Key.Code} State={stroke.Key.State}"); var deviceHwStr = InterceptionDriver.GetHardwareStr(_inteceptionContext, deviceId); // only handle if string test passes: if (Array.Find(deviceStringListToTest, p => deviceHwStr.StartsWith(p)) != null) { foreach (IClickerTarget client in _targets) { if (!client.IsActive()) { continue; } else { handledByClientName = client.GetType().Name; System.Diagnostics.Debug.WriteLine($"{handledByClientName} {stroke.Key.Code}"); if (stroke.Key.Code == Interception.Keys.Right) { System.Diagnostics.Debug.WriteLine("Right"); client.SendNext(); } else if (stroke.Key.Code == Interception.Keys.Left) { System.Diagnostics.Debug.WriteLine("Left"); client.SendPrevious(); } isHandled = true; break; } } OnKeyPressed(new KeyPressedHandledEventArgs(handledByClientName)); } } // pass-through if unhandled // (or your normal PC keyboard won't work!) if (!isHandled) { InterceptionDriver.Send(_inteceptionContext, deviceId, ref stroke, 1); } } Abort(); }