Beispiel #1
0
        private void InputInterceptor_VirtualMouseAction(object sender, MousePressedEventArgs e)
        {
            if (e.State != MouseState.LeftDown)
            {
                return;
            }

            Application.Current.Dispatcher.Invoke(() =>
            {
                var lastKnown = _inputInterceptor.Mice[e.DeviceId].PreMouseData;
                var container = Conatainer[e.DeviceId];

                var positon             = new Point(lastKnown.AbsolutX, lastKnown.AbsolutY);
                var elementsUnderCursor = new List <DependencyObject>();
                //var hasHitTest = VisualTreeHelper.HitTest(container, positon);

                if (!GetExactHitTest(container, container, positon, elementsUnderCursor))
                {
                    return;
                }

                var findTextBox = GetVisualParentWithKeyHandling(elementsUnderCursor.Last());
                var addOrUpdate = FocusedElements.AddOrUpdate(e.DeviceId, findTextBox,
                                                              (key, old) =>
                {
                    RemoveOld(old);
                    return(findTextBox);
                });
                AddNew(addOrUpdate);
                Console.WriteLine("Current Focused: " + addOrUpdate);
            }, DispatcherPriority.Input);
        }
 public InputTuple(bool natural, int mouseDevice, int keyboardDevice)
 {
     Natural        = natural;
     MouseDevice    = mouseDevice;
     KeyboardDevice = keyboardDevice;
     LastMouseData  = new MousePressedEventArgs(0);
     LastKeyData    = new KeyPressedEventArgs();
     PreMouseData   = new MousePressedEventArgs(0);
     PreKeyData     = new KeyPressedEventArgs();
 }
 private void InputOnMouseAction(object sender, MousePressedEventArgs e)
 {
     e.DeviceId = DeviceMap[e.DeviceName].PersistantId;
     if (Mice.ContainsKey(e.DeviceId))
     {
         var inputTuple = Mice[e.DeviceId];
         if (!inputTuple.Natural)
         {
             inputTuple.PreMouseData  = inputTuple.LastMouseData;
             inputTuple.LastMouseData = e;
             OnVirtualMouseAction(e);
             e.Handled = true;
         }
     }
 }
Beispiel #4
0
        private void Input_OnMousePressed(object sender, MousePressedEventArgs e)
        {
            if (e.State > MouseState.LeftUp)
            {
                KeyStroke stroke = KeyStroke.MouseStroke(e.State);

                if (isAwaitingNormalKey || isAwaitingSwitchedKey)
                {
                    bool isNormal = isAwaitingNormalKey;
                    BindingList <KeyStroke> keyList = isNormal ? normalKeys : switchedKeys;

                    if (!keyList.Contains(stroke))
                    {
                        this.Invoke((MethodInvoker) delegate
                        {
                            keyList.Add(stroke);
                            saveSettings();
                        });

                        isAwaitingSwitchedKey = false;
                        isAwaitingNormalKey   = false;
                    }
                    return;
                }

                bool switchContained = switchedKeys.Contains(stroke);
                bool normalContained = normalKeys.Contains(stroke);
                if (switchContained && normalContained)
                {
                    isMouseSpeedSwitched = !isMouseSpeedSwitched;
                }
                else if (switchContained)
                {
                    isMouseSpeedSwitched = true;
                }
                else if (normalContained)
                {
                    isMouseSpeedSwitched = false;
                }
            }

            e.X *= isMouseSpeedSwitched ? switchedXMultiplier : normalXMultiplier;
            e.Y *= isMouseSpeedSwitched ? switchedYMultiplier : normalYMultiplier;
        }
        private void InputInterceptorVirtualMouseAction(object sender, MousePressedEventArgs e)
        {
            if (e.DeviceId != _mouseId)
            {
                return;
            }

            MousePressedEventArgs lastKnown = null;
            Point worldCoodinates           = new Point();

            Application.Current.Dispatcher.Invoke(() =>
            {
                lastKnown       = _inputInterceptor.Mice[e.DeviceId].LastMouseData;
                var destination = new Point(Canvas.GetLeft(VirtualMouse) + lastKnown.X, Canvas.GetTop(VirtualMouse) + lastKnown.Y);

                if (CheckBounds(lastKnown.X, lastKnown.Y))
                {
                    Canvas.SetTop(VirtualMouse, destination.Y);
                    Canvas.SetLeft(VirtualMouse, destination.X);
                    lastKnown.AbsolutX = (int)destination.X;
                    lastKnown.AbsolutY = (int)destination.Y;
                }

                if (lastKnown.State == MouseState.Undefined)
                {
                    return;
                }

                worldCoodinates = AssociatedObject.TranslatePoint(destination, Application.Current.MainWindow);
            }, DispatcherPriority.Send);

            bool handeld             = false;
            var  elementsUnderCursor = new List <DependencyObject>();

            Application.Current.Dispatcher.Invoke(() =>
            {
                var positon = new Point(lastKnown.AbsolutX, lastKnown.AbsolutY);
                if (!GameAreaFocusService.GetExactHitTest(LayoutBounds, LayoutBounds, positon, elementsUnderCursor))
                {
                    return;
                }

                var findScrollProvider = elementsUnderCursor
                                         .Select(GameAreaFocusService.GetVisualParentWithKeyHandling)
                                         .FirstOrDefault(f => f != null);
                if (findScrollProvider == null)
                {
                    return;
                }

                var firstOrDefault = Interaction.GetBehaviors(findScrollProvider).FirstOrDefault(f => f is IVirtualInputReciver) as IVirtualInputReciver;
                handeld            = firstOrDefault.ReciveMouseInput(lastKnown);
            }, DispatcherPriority.Send);
            if (handeld)
            {
                return;
            }
            if (lastKnown.State == MouseState.Undefined)
            {
                return;
            }
            var btnMessages = new MSG[0];

            if (lastKnown.State == MouseState.LeftDown || lastKnown.State == MouseState.LeftUp)
            {
                btnMessages = SendMessageApi.GetControlClickMessages("left", lastKnown.State == MouseState.LeftDown,
                                                                     (int)worldCoodinates.X, (int)worldCoodinates.Y);
            }
            else if (lastKnown.State == MouseState.RightDown || lastKnown.State == MouseState.RightUp)
            {
                btnMessages = SendMessageApi.GetControlClickMessages("right", lastKnown.State == MouseState.RightDown,
                                                                     (int)worldCoodinates.X, (int)worldCoodinates.Y);
            }
            else if (lastKnown.State == MouseState.MiddleDown || lastKnown.State == MouseState.MiddleUp)
            {
                btnMessages = SendMessageApi.GetControlClickMessages("middle", lastKnown.State == MouseState.MiddleDown,
                                                                     (int)worldCoodinates.X, (int)worldCoodinates.Y);
            }
            else if (lastKnown.State == MouseState.ScrollDown)
            {
                Application.Current.Dispatcher.Invoke(() =>
                {
                    var findScrollProvider = GameAreaFocusService.GetVisualParent <ScrollViewer>(elementsUnderCursor.Last());
                    if (findScrollProvider != null)
                    {
                        findScrollProvider.ScrollToVerticalOffset(lastKnown.Rolling);
                    }
                    else
                    {
                        var dependencyObject    = elementsUnderCursor.Last();
                        var mouseWheelEventArgs = new MouseWheelEventArgs(InputManager.Current.PrimaryMouseDevice, 0, lastKnown.Rolling);

                        mouseWheelEventArgs.RoutedEvent = UIElement.MouseWheelEvent;
                        mouseWheelEventArgs.Source      = this;
                        (dependencyObject as UIElement).RaiseEvent(mouseWheelEventArgs);
                    }
                }, DispatcherPriority.Send);
            }

            foreach (var msg in btnMessages)
            {
                SendMessageApi.SendMessageTo(_windowHandle, msg.message, msg.wParam, msg.lParam);
            }
        }
Beispiel #6
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();
        }
Beispiel #7
0
 /// <inheritdoc />
 public virtual bool ReciveMouseInput(MousePressedEventArgs mouseEvent)
 {
     return(false);
 }
Beispiel #8
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();
        }
        /// <inheritdoc />
        public bool ReciveMouseInput(MousePressedEventArgs mouseEvent)
        {
            browserHost = browserHost ?? AssociatedObject.GetBrowser().GetHost();
            if (!_gameAreaFocusService.Conatainer.ContainsKey(mouseEvent.DeviceId))
            {
                return(false);
            }

            var dependencyObject = _gameAreaFocusService.Conatainer[mouseEvent.DeviceId];

            if (dependencyObject == null)
            {
                return(false);
            }

            return(AssociatedObject.Dispatcher.Invoke(() =>
            {
                var translatePoint = dependencyObject.TranslatePoint(new Point(mouseEvent.AbsolutX, mouseEvent.AbsolutY),
                                                                     AssociatedObject);
                var chromeMouseEvent = new MouseEvent((int)translatePoint.X, (int)translatePoint.Y, CefEventFlags.None);

                MouseButtonType mouseType = MouseButtonType.Left;
                var mouseUp = false;

                switch (mouseEvent.State)
                {
                case MouseState.Undefined:
                    browserHost.SendMouseMoveEvent(chromeMouseEvent, false);
                    return true;

                case MouseState.LeftDown:
                    mouseType = MouseButtonType.Left;
                    break;

                case MouseState.LeftUp:
                    mouseUp = true;
                    mouseType = MouseButtonType.Left;
                    break;

                case MouseState.RightDown:
                    mouseType = MouseButtonType.Right;
                    break;

                case MouseState.RightUp:
                    mouseUp = true;
                    mouseType = MouseButtonType.Right;
                    break;

                case MouseState.MiddleDown:
                    mouseType = MouseButtonType.Middle;
                    break;

                case MouseState.MiddleUp:
                    mouseUp = true;
                    mouseType = MouseButtonType.Middle;
                    break;

                case MouseState.LeftExtraDown:
                    mouseType = MouseButtonType.Left;
                    break;

                case MouseState.LeftExtraUp:
                    mouseUp = true;
                    mouseType = MouseButtonType.Left;
                    break;

                case MouseState.RightExtraDown:
                    mouseType = MouseButtonType.Right;
                    break;

                case MouseState.RightExtraUp:
                    mouseUp = true;
                    mouseType = MouseButtonType.Right;
                    break;

                default:
                    return false;

                    throw new ArgumentOutOfRangeException();
                }

                browserHost.SendMouseClickEvent(chromeMouseEvent, mouseType, mouseUp, 1);
                return true;
            }, DispatcherPriority.Send));
        }
 protected virtual void OnVirtualMouseAction(MousePressedEventArgs e)
 {
     VirtualMouseAction?.Invoke(this, e);
 }