public void CreateContext()
 {
     if (IsContextCreated == false)
     {
         context          = InterceptionDriver.CreateContext();
         IsContextCreated = true;
     }
 }
Esempio n. 2
0
        private void Start()
        {
            context = InterceptionDriver.CreateContext();

            ni.BalloonTipIcon  = System.Windows.Forms.ToolTipIcon.None;
            ni.BalloonTipTitle = "BMS2";

            if (context != IntPtr.Zero)
            {
                callbackThread              = new Thread(new ThreadStart(hook));
                callbackThread.Priority     = ThreadPriority.Highest;
                callbackThread.IsBackground = true;
                callbackThread.Start();
            }
            ch_work();
        }
Esempio n. 3
0
        public void WaitForCmd()
        {
            IntPtr ctx    = InterceptionDriver.CreateContext();
            int    device = 0;
            Stroke strk   = new Stroke();

            InterceptionDriver.SetFilter(ctx, InterceptionDriver.IsKeyboard, (int)KeyboardFilterMode.KeyDown | (int)KeyboardFilterMode.KeyUp);

            int i = 0;

            while (InterceptionDriver.Receive(ctx, device = InterceptionDriver.Wait(ctx), ref strk, 1) > 0)
            {
#if DEBUG
                Console.WriteLine((int)strk.Key.Code);
#endif
                if (strk.Key.Code == (Keys)powerKey)
                {
                    ++i;
                    if (i < 2)
                    {
                        continue;
                    }
                    lock (thisLock)
                    {
                        if (IsRunning())
                        {
                            Stop();

#if DEBUG
                            Console.WriteLine("Stop");
#endif
                        }
                        else
                        {
                            Start();

#if DEBUG
                            Console.WriteLine("Start");
#endif
                        }
                    }
                    i = 0;
                }
                InterceptionDriver.Send(ctx, device, ref strk, 1);
            }
        }
Esempio n. 4
0
        private void Start()
        {
            context = InterceptionDriver.CreateContext();

            if (context != IntPtr.Zero)
            {
                callbackThread = new Thread(new ThreadStart(hook))
                {
                    Priority     = ThreadPriority.Highest,
                    IsBackground = true
                };
                callbackThread.Start();
            }

            Thread tmr = new Thread(_timer)
            {
                IsBackground = true
            };

            tmr.Start();
        }
        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();
        }