Esempio n. 1
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. 2
0
        private void hook()
        {
            bool s  = true;
            bool l1 = true;
            bool l2 = true;

            Stroke stroke = new Stroke();

            InterceptionDriver.SetFilter(context, InterceptionDriver.IsKeyboard, (Int32)KeyboardFilterMode.All);
            InterceptionDriver.SetFilter(context, InterceptionDriver.IsMouse, (Int32)MouseFilterMode.All);

            //keyboard: device=3
            //mouse: device=11

            while (InterceptionDriver.Receive(context, device = InterceptionDriver.Wait(context), ref stroke, 1) > 0)
            {
                s = true;
                if (InterceptionDriver.IsMouse(device) > 0)
                {
                    if (l1)
                    {
                        l1   = false;
                        devm = device;
                        Dispatcher.Invoke(() => { label1.Content = device; });
                    }

                    if (OnMousePressed != null)
                    {
                        var args = new MousePressedEventArgs()
                        {
                            X = stroke.Mouse.X, Y = stroke.Mouse.Y, State = stroke.Mouse.State, Rolling = stroke.Mouse.Rolling
                        };
                        OnMousePressed(this, args);

                        if (args.Handled)
                        {
                            continue;
                        }
                        stroke.Mouse.X       = args.X;
                        stroke.Mouse.Y       = args.Y;
                        stroke.Mouse.State   = args.State;
                        stroke.Mouse.Rolling = args.Rolling;
                    }
                }

                if (InterceptionDriver.IsKeyboard(device) > 0)
                {
                    if (l2)
                    {
                        l2   = false;
                        devk = device;
                        Dispatcher.Invoke(() => { label2.Content = device; });
                    }

                    if (stroke.Key.Code == Keys.Tilde)
                    {
                        if (work)
                        {
                            if (bss)
                            {
                                if (stroke.Key.State == KeyState.Down)
                                {
                                    if (mss == false)
                                    {
                                        m   = false;
                                        mss = true;
                                        new Thread(macross).Start();
                                    }
                                }
                                else
                                if (stroke.Key.State == KeyState.Up)
                                {
                                    if (mss == true)
                                    {
                                        mss = false;
                                    }
                                }

                                s = false;
                            }
                        }
                    }

                    if (stroke.Key.Code == Keys.One)
                    {
                        if (work)
                        {
                            if (bs1)
                            {
                                if (stroke.Key.State == KeyState.Down)
                                {
                                    m = false;
                                }
                            }
                        }
                    }

                    if (stroke.Key.Code == Keys.Z)
                    {
                        if (work)
                        {
                            if (bs2)
                            {
                                if (stroke.Key.State == KeyState.Down)
                                {
                                    m = false;
                                }
                            }
                        }
                    }

                    if (stroke.Key.Code == Keys.Three)
                    {
                        if (work)
                        {
                            if (bs3)
                            {
                                if (stroke.Key.State == KeyState.Down)
                                {
                                    m = false;
                                }
                            }
                        }
                    }

                    if (stroke.Key.Code == Keys.Four)
                    {
                        if (work)
                        {
                            if (bs4)
                            {
                                if (stroke.Key.State == KeyState.Down)
                                {
                                    m = false;
                                }
                            }
                        }
                    }

                    if (stroke.Key.Code == Keys.R)
                    {
                        if (work)
                        {
                            if (bpw)
                            {
                                if (stroke.Key.State == KeyState.Up)
                                {
                                    if (m == false)
                                    {
                                        m = true;
                                        if (mt)
                                        {
                                            new Thread(macro_text).Start();
                                        }
                                        else
                                        {
                                            new Thread(macro).Start();
                                        }
                                    }
                                    else
                                    {
                                        m = false;
                                    }
                                }
                            }
                            else
                            {
                                if (stroke.Key.State == KeyState.Down)
                                {
                                    if (m == false)
                                    {
                                        m = true;
                                        if (mt)
                                        {
                                            new Thread(macro_text).Start();
                                        }
                                        else
                                        {
                                            new Thread(macro).Start();
                                        }
                                    }
                                }
                                else
                                if (stroke.Key.State == KeyState.Up)
                                {
                                    if (m == true)
                                    {
                                        m = false;
                                    }
                                }
                            }

                            s = false;
                        }
                    }

                    if (stroke.Key.Code == Keys.T)
                    {
                        if (work)
                        {
                            if (bt)
                            {
                                if (stroke.Key.State == KeyState.Down)
                                {
                                    if (m2 == false)
                                    {
                                        m  = false;
                                        m2 = true;
                                        new Thread(macro2).Start();
                                    }
                                }
                                else
                                if (stroke.Key.State == KeyState.Up)
                                {
                                    if (m2 == true)
                                    {
                                        m2 = false;
                                    }
                                }

                                s = false;
                            }
                        }
                    }

                    if (stroke.Key.Code == Keys.Insert)
                    {
                        if (stroke.Key.State == KeyState.E0)
                        {
                            if (pause_exit)
                            {
                                Stop();
                            }
                            new Thread(timer).Start();
                            new Thread(ch_work).Start();
                            s = false;
                        }
                    }

                    if (stroke.Key.Code == Keys.Enter)
                    {
                        if (stroke.Key.State == KeyState.Down)
                        {
                            if (work == true)
                            {
                                new Thread(ch_work).Start();
                                m = false;
                            }
                        }
                    }

                    if (OnKeyPressed != null)
                    {
                        var args = new KeyPressedEventArgs()
                        {
                            Key = stroke.Key.Code, State = stroke.Key.State
                        };
                        OnKeyPressed(this, args);

                        if (args.Handled)
                        {
                            continue;
                        }
                        stroke.Key.Code  = args.Key;
                        stroke.Key.State = args.State;
                    }
                }

                if (s)
                {
                    InterceptionDriver.Send(context, device, ref stroke, 1);
                }
            }

            Stop();
        }
 private void InitKeyboardDriver()
 {
     CreateContext();
     InterceptionDriver.SetFilter(context, InterceptionDriver.IsKeyboard, (int)KeyboardFilterMode.All);
 }
        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();
        }
Esempio n. 5
0
        private void hook()
        {
            bool s      = true;
            bool l1     = true;
            bool l2     = true;
            bool winkey = false;

            Stroke stroke = new Stroke();

            InterceptionDriver.SetFilter(context, InterceptionDriver.IsMouse, (Int32)MouseFilterMode.All);
            InterceptionDriver.SetFilter(context, InterceptionDriver.IsKeyboard, (Int32)KeyboardFilterMode.All);

            while (InterceptionDriver.Receive(context, device = InterceptionDriver.Wait(context), ref stroke, 1) > 0)
            {
                s = true;
                if (InterceptionDriver.IsMouse(device) > 0)
                {
                    if (l1)
                    {
                        l1   = false;
                        devm = device;
                    }
                    user_out = false;
                    if (_lock)
                    {
                        s = false;
                    }

                    if (OnMousePressed != null)
                    {
                        var args = new MousePressedEventArgs()
                        {
                            X = stroke.Mouse.X, Y = stroke.Mouse.Y, State = stroke.Mouse.State, Rolling = stroke.Mouse.Rolling
                        };
                        OnMousePressed(this, args);

                        if (args.Handled)
                        {
                            continue;
                        }
                        stroke.Mouse.X       = args.X;
                        stroke.Mouse.Y       = args.Y;
                        stroke.Mouse.State   = args.State;
                        stroke.Mouse.Rolling = args.Rolling;
                    }
                }

                if (InterceptionDriver.IsKeyboard(device) > 0)
                {
                    if (l2)
                    {
                        l2   = false;
                        devk = device;
                    }

                    if (_lock)
                    {
                        s = false;
                    }

                    user_out = false;

                    if ((stroke.Key.Code == Keys.WindowsKeyLeft) | (stroke.Key.Code == Keys.WindowsKeyRight))
                    {
                        if (stroke.Key.State == KeyState.E0)
                        {
                            winkey = true;
                        }
                        else
                        {
                            winkey = false;
                        }
                    }

                    if (stroke.Key.Code == Keys.NumpadMinus)
                    {
                        try
                        {
                            Thread blk = new Thread(block);
                            blk.IsBackground = true;
                            blk.Start();

                            s = false;
                        }
                        catch { System.Windows.MessageBox.Show("Error"); }
                    }

                    if (stroke.Key.Code == Keys.Q)
                    {
                        if (winkey)
                        {
                            try
                            {
                                Thread unblk = new Thread(unblock);
                                unblk.IsBackground = true;
                                unblk.Start();
                            }
                            catch { System.Windows.MessageBox.Show("Error"); }
                        }
                    }

                    if (OnKeyPressed != null)
                    {
                        var args = new KeyPressedEventArgs()
                        {
                            Key = stroke.Key.Code, State = stroke.Key.State
                        };
                        OnKeyPressed(this, args);

                        if (args.Handled)
                        {
                            continue;
                        }
                        stroke.Key.Code  = args.Key;
                        stroke.Key.State = args.State;
                    }
                }

                if (s)
                {
                    InterceptionDriver.Send(context, device, ref stroke, 1);
                }
            }

            Stop();
        }