Exemplo n.º 1
0
        private void DriverCallback()
        {
            InterceptionDriver.SetFilter(context, InterceptionDriver.IsKeyboard, (Int32) KeyboardFilterMode);
            InterceptionDriver.SetFilter(context, InterceptionDriver.IsMouse, (Int32) MouseFilterMode);

            Stroke stroke = new Stroke();

            while (InterceptionDriver.Receive(context, deviceId = InterceptionDriver.Wait(context), ref stroke, 1) > 0)
            {
                if (InterceptionDriver.IsMouse(deviceId) > 0)
                {
                    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(deviceId) > 0)
                {
                    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;
                    }
                }

                InterceptionDriver.Send(context, deviceId, ref stroke, 1);
            }

            Unload();
            throw new Exception("Interception.Receive() failed for an unknown reason. The driver has been unloaded.");
        }
Exemplo n.º 2
0
        public void SendKey(Keys key, KeyState state)
        {
            Stroke stroke = new Stroke();
            KeyStroke keyStroke = new KeyStroke();

            keyStroke.Code = key;
            keyStroke.State = state;

            stroke.Key = keyStroke;

            InterceptionDriver.Send(context, deviceId, ref stroke, 1);

            if (KeyPressDelay > 0)
                Thread.Sleep(KeyPressDelay);
        }
Exemplo n.º 3
0
        public void SendMouseEvent(MouseState state)
        {
            Stroke stroke = new Stroke();
            MouseStroke mouseStroke = new MouseStroke();

            mouseStroke.State = state;

            if (state == MouseState.ScrollUp)
            {
                mouseStroke.Rolling = 120;
            }
            else if (state == MouseState.ScrollDown)
            {
                mouseStroke.Rolling = -120;
            }

            stroke.Mouse = mouseStroke;

            InterceptionDriver.Send(context, 12, ref stroke, 1);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Warning: This function, if using the driver, does not function reliably and often moves the mouse in unpredictable vectors. An alternate version uses the standard Win32 API to get the current cursor's position, calculates the desired destination's offset, and uses the Win32 API to set the cursor to the new position.
        /// </summary>
        public void MoveMouseBy(int deltaX, int deltaY, bool useDriver = false)
        {
            if (useDriver)
            {
                Stroke stroke = new Stroke();
                MouseStroke mouseStroke = new MouseStroke();

                mouseStroke.X = deltaX;
                mouseStroke.Y = deltaY;

                stroke.Mouse = mouseStroke;
                stroke.Mouse.Flags = MouseFlags.MoveRelative;

                InterceptionDriver.Send(context, 12, ref stroke, 1);
            }
            else
            {
                var currentPos = Cursor.Position;
                Cursor.Position = new Point(currentPos.X + deltaX, currentPos.Y - deltaY); // Coordinate system for y: 0 begins at top, and bottom of screen has the largest number
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Warning: This function, if using the driver, does not function reliably and often moves the mouse in unpredictable vectors. An alternate version uses the standard Win32 API to set the cursor's position and does not use the driver.
        /// </summary>
        public void MoveMouseTo(int x, int y, bool useDriver = false)
        {
            if (useDriver)
            {
                Stroke stroke = new Stroke();
                MouseStroke mouseStroke = new MouseStroke();

                mouseStroke.X = x;
                mouseStroke.Y = y;

                stroke.Mouse = mouseStroke;
                stroke.Mouse.Flags = MouseFlags.MoveAbsolute;

                InterceptionDriver.Send(context, 12, ref stroke, 1);
            }
            {
                Cursor.Position = new Point(x, y);
            }
        }
Exemplo n.º 6
0
        public void SendKey(Keys key)
        {
            Stroke stroke = new Stroke();
            KeyStroke keyStroke = new KeyStroke();

            keyStroke.Code = key;
            keyStroke.State = KeyState.Down;

            stroke.Key = keyStroke;

            InterceptionDriver.Send(context, 1, ref stroke, 1);

            stroke.Key.State = KeyState.Up;
            InterceptionDriver.Send(context, 1, ref stroke, 1);
        }
Exemplo n.º 7
0
        public void SendKeys(params Keys[] keys)
        {
            Stroke stroke = new Stroke();
            KeyStroke keyStroke = new KeyStroke();

            foreach (Keys key in keys)
            {
                keyStroke.Code = key;
                keyStroke.State = 0;

                stroke.Key = keyStroke;

                InterceptionDriver.Send(context, 1, ref stroke, 1);
            }

            foreach (Keys key in keys)
            {
                keyStroke.Code = key;
                keyStroke.State = KeyState.Up;

                stroke.Key = keyStroke;

                InterceptionDriver.Send(context, 1, ref stroke, 1);
            }
        }
Exemplo n.º 8
0
        public void SendKey(Keys key, KeyState state)
        {
            Stroke stroke = new Stroke();
            KeyStroke keyStroke = new KeyStroke();

            keyStroke.Code = key;
            keyStroke.State = state;

            stroke.Key = keyStroke;

            InterceptionDriver.Send(context, 1, ref stroke, 1);
        }
Exemplo n.º 9
0
        public void MoveMouseBy(int deltaX, int deltaY)
        {
            Stroke stroke = new Stroke();
            MouseStroke mouseStroke = new MouseStroke();

            mouseStroke.X = deltaX;
            mouseStroke.Y = deltaY;

            stroke.Mouse = mouseStroke;
            stroke.Mouse.Flags = MouseFlags.MoveRelative;

            InterceptionDriver.Send(context, 12, ref stroke, 1);
        }
Exemplo n.º 10
0
 public static extern Int32 Send(IntPtr context, Int32 device, ref Stroke stroke, UInt32 numStrokes);
Exemplo n.º 11
0
 public static extern Int32 Receive(IntPtr context, Int32 device, ref Stroke stroke, UInt32 numStrokes);
Exemplo n.º 12
0
        private void DriverCallback()
        {
            InterceptionDriver.SetFilter(context, InterceptionDriver.IsKeyboard, (Int32)KeyboardFilterMode);
            InterceptionDriver.SetFilter(context, InterceptionDriver.IsMouse, (Int32)MouseFilterMode);

            Stroke stroke = new Stroke();

            int deviceId = -1;

            while (InterceptionDriver.Receive(context, deviceId = InterceptionDriver.Wait(context), ref stroke, 1) > 0)
            {
                if (InterceptionDriver.IsMouse(deviceId) > 0)
                {
                    if (deviceId != mouseDeviceId)
                    {
                        mouseDeviceId = deviceId;
                        this.debug("Mouse device detected. Id updated to " + mouseDeviceId);
                    }

                    if (OnMousePressed != null)
                    {
                        var args = new MousePressedEventArgs()
                        {
                            DeviceId = deviceId, 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(deviceId) > 0)
                {
                    if (deviceId != keyboardDeviceId)
                    {
                        keyboardDeviceId = deviceId;
                        this.debug("Keyboard device detected. Id updated to " + keyboardDeviceId);
                    }

                    if (OnKeyPressed != null)
                    {
                        var args = new KeyPressedEventArgs()
                        {
                            DeviceId = deviceId, 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;
                    }
                }

                InterceptionDriver.Send(context, deviceId, ref stroke, 1);
            }

            Unload();
            throw new Exception("Interception.Receive() failed for an unknown reason. The driver has been unloaded.");
        }