ACAT.Lib.Core.Utility.User32Interop.SendInput C# (CSharp) Метод

SendInput() приватный Метод

private SendInput ( uint nInputs, INPUT &pInputs, int cbSize ) : uint
nInputs uint
pInputs INPUT
cbSize int
Результат uint
        public static extern uint SendInput(uint nInputs, ref INPUT pInputs, int cbSize);

Usage Example

Пример #1
0
        /// <summary>
        /// Simulates mouse left click at the indicated
        /// by doing a mouse down followed by a mouse up
        /// </summary>
        /// <param name="x">x position of cursor</param>
        /// <param name="y">y position of the cursor</param>
        public static void ClickLeftMouseButton(int x, int y)
        {
            float screenWidth  = Screen.PrimaryScreen.Bounds.Width;
            float screenHeight = Screen.PrimaryScreen.Bounds.Height;

            var mouseInput = new User32Interop.INPUT {
                type = User32Interop.SendInputEventType.InputMouse
            };

            //mouseInput.mkhi.mi.dx = x;
            //mouseInput.mkhi.mi.dy = y;

            mouseInput.mkhi.mi.dx        = (int)Math.Round(x * (65535 / screenWidth), 0);
            mouseInput.mkhi.mi.dy        = (int)Math.Round(y * (65535 / screenHeight), 0);
            mouseInput.mkhi.mi.mouseData = 0;

            mouseInput.mkhi.mi.dwFlags = User32Interop.MouseEventFlags.MOUSEEVENTF_MOVE |
                                         User32Interop.MouseEventFlags.MOUSEEVENTF_ABSOLUTE;
            User32Interop.SendInput(1, ref mouseInput, Marshal.SizeOf(new User32Interop.INPUT()));

            var inputDown = new User32Interop.INPUT();

            inputDown.mkhi.mi.dx        = 0;
            inputDown.mkhi.mi.dy        = 0;
            inputDown.mkhi.mi.mouseData = 0;
            inputDown.mkhi.mi.dwFlags   = User32Interop.MouseEventFlags.MOUSEEVENTF_LEFTDOWN;
            User32Interop.SendInput(1, ref inputDown, Marshal.SizeOf(new User32Interop.INPUT()));

            inputDown.mkhi.mi.dwFlags = User32Interop.MouseEventFlags.MOUSEEVENTF_LEFTUP;
            User32Interop.SendInput(1, ref inputDown, Marshal.SizeOf(new User32Interop.INPUT()));
        }