Exemplo n.º 1
0
 public static void InitMouseInput(out Input input, int x, int y, MouseInputFlags flags, uint data = 0,
                                   uint timestampMillis = 0)
 {
     input = new Input
     {
         Type   = InputType.INPUT_MOUSE,
         Packet = new InputPacket
         {
             MouseInput =
             {
                 Time  = timestampMillis,
                 X     = x,
                 Y     = y,
                 Data  = data,
                 Flags = flags
             }
         }
     };
 }
Exemplo n.º 2
0
        private void VerifyMouseButtonCall(MouseInputFlags flags, int x = -1, int y = -1)
        {
            Func<Input[], bool> hasMatchingCoordinates = inputs =>
            {
                var input = inputs.Single().Data.Mouse;
                //intentional +1 after experimenting a bit with how SendInput
                //handles the transformation to screen normalized coordinates
                return input.X == (x + 1) && input.Y == (y + 1);
            };
            Func<Input[], bool> hasMatchingFlags = inputs =>
            {
                var input = inputs.Single().Data.Mouse;
                return input.Flags == flags;
            };

            Func<Input[], bool> hasMatchingInput = inputs => hasMatchingCoordinates(inputs) && hasMatchingFlags(inputs);

            A.CallTo(() => this.nativeMethodWrapper.SendInput(A<Input[]>.That.Matches(hasMatchingInput,
                                                                           "input to send input did not match")))
             .MustHaveHappened();
        }
Exemplo n.º 3
0
        private static void PerformMouseAction(int coord_x, int coord_y, int something, MouseInputFlags flags)
        {
            PermissionSet permissions = new PermissionSet(PermissionState.Unrestricted);
            permissions.Demand();

            int intflags = (int)flags;

            if ((intflags & (int)MouseInputFlags.Absolute) != 0)
            {
                // Absolute position requires normalized coordinates.
                NormalizeCoordinates(ref coord_x, ref coord_y);
                intflags |= MouseeventfVirtualdesk;
            }

            INPUT mi = new INPUT();
            mi.type = InputMouse;
            mi.union.mouseInput.dx = coord_x;
            mi.union.mouseInput.dy = coord_y;
            mi.union.mouseInput.mouseData = something;
            mi.union.mouseInput.dwFlags = intflags;
            mi.union.mouseInput.time = 0;
            mi.union.mouseInput.dwExtraInfo = new IntPtr(0);

            if (SendInput(1, ref mi, Marshal.SizeOf(mi)) == 0)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }
        }
Exemplo n.º 4
0
        private static void PerformMouseAction(int coord_x, int coord_y, int something, MouseInputFlags flags)
        {
            PermissionSet permissions = new PermissionSet(PermissionState.Unrestricted);

            permissions.Demand();

            int intflags = (int)flags;

            if ((intflags & (int)MouseInputFlags.Absolute) != 0)
            {
                // Absolute position requires normalized coordinates.
                NormalizeCoordinates(ref coord_x, ref coord_y);
                intflags |= MouseeventfVirtualdesk;
            }

            INPUT mi = new INPUT();

            mi.type = InputMouse;
            mi.union.mouseInput.dx          = coord_x;
            mi.union.mouseInput.dy          = coord_y;
            mi.union.mouseInput.mouseData   = something;
            mi.union.mouseInput.dwFlags     = intflags;
            mi.union.mouseInput.time        = 0;
            mi.union.mouseInput.dwExtraInfo = new IntPtr(0);

            if (SendInput(1, ref mi, Marshal.SizeOf(mi)) == 0)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }
        }