Esempio n. 1
0
        public static void MoveTo(AutomationElement element)
        {
            var rect = element.Current.BoundingRectangle;
            int x    = (int)(rect.Left + (rect.Width / 2));
            int y    = (int)(rect.Top + (rect.Height / 2));

            x = (int)(x * (65536.0f / NativeMethods.GetSystemMetrics((int)NativeEnums.MetricIndex.SM_CXSCREEN)));
            y = (int)(y * (65536.0f / NativeMethods.GetSystemMetrics((int)NativeEnums.MetricIndex.SM_CYSCREEN)));

            NativeStructs.Input input = new NativeStructs.Input
            {
                type       = NativeEnums.SendInputEventType.Mouse,
                mouseInput = new NativeStructs.MouseInput
                {
                    dx          = x,
                    dy          = y,
                    mouseData   = 0,
                    dwFlags     = NativeEnums.MouseEventFlags.Absolute | NativeEnums.MouseEventFlags.Move,
                    time        = 0,
                    dwExtraInfo = IntPtr.Zero,
                },
            };

            NativeMethods.SendInput(1, ref input, Marshal.SizeOf(input));
        }
        public static void LeftClick()
        {
            NativeStructs.Input input = new NativeStructs.Input
            {
                type = NativeEnums.SendInputEventType.Mouse,
                mouseInput = new NativeStructs.MouseInput
                {
                    dx = 0,
                    dy = 0,
                    mouseData = 0,
                    dwFlags = NativeEnums.MouseEventFlags.Absolute | NativeEnums.MouseEventFlags.LeftDown,
                    time = 0,
                    dwExtraInfo = IntPtr.Zero,
                },
            };

            NativeMethods.SendInput(1, ref input, Marshal.SizeOf(input));

            input.mouseInput.dwFlags = NativeEnums.MouseEventFlags.Absolute | NativeEnums.MouseEventFlags.LeftUp;

            NativeMethods.SendInput(1, ref input, Marshal.SizeOf(input));
        }
Esempio n. 3
0
        public static void LeftClick()
        {
            NativeStructs.Input input = new NativeStructs.Input
            {
                type       = NativeEnums.SendInputEventType.Mouse,
                mouseInput = new NativeStructs.MouseInput
                {
                    dx          = 0,
                    dy          = 0,
                    mouseData   = 0,
                    dwFlags     = NativeEnums.MouseEventFlags.Absolute | NativeEnums.MouseEventFlags.LeftDown,
                    time        = 0,
                    dwExtraInfo = IntPtr.Zero,
                },
            };

            NativeMethods.SendInput(1, ref input, Marshal.SizeOf(input));

            input.mouseInput.dwFlags = NativeEnums.MouseEventFlags.Absolute | NativeEnums.MouseEventFlags.LeftUp;

            NativeMethods.SendInput(1, ref input, Marshal.SizeOf(input));
        }
        public static void MoveTo(AutomationElement element)
        {
            var rect = element.Current.BoundingRectangle;
            int x = (int)(rect.Left + (rect.Width / 2));
            int y = (int)(rect.Top + (rect.Height / 2));
            x = (int)(x * (65536.0f / NativeMethods.GetSystemMetrics((int)NativeEnums.MetricIndex.SM_CXSCREEN)));
            y = (int)(y * (65536.0f / NativeMethods.GetSystemMetrics((int)NativeEnums.MetricIndex.SM_CYSCREEN)));

            NativeStructs.Input input = new NativeStructs.Input
            {
                type = NativeEnums.SendInputEventType.Mouse,
                mouseInput = new NativeStructs.MouseInput 
                    {
                        dx = x,
                        dy = y,
                        mouseData = 0,
                        dwFlags = NativeEnums.MouseEventFlags.Absolute | NativeEnums.MouseEventFlags.Move,
                        time = 0,
                        dwExtraInfo = IntPtr.Zero,
                    },
            };

            NativeMethods.SendInput(1, ref input, Marshal.SizeOf(input));            
        }
Esempio n. 5
0
 internal static extern uint SendInput(uint nInputs, ref NativeStructs.Input pInputs, int cbSize);