예제 #1
0
        public static void MouseLeftPress(int x, int y)
        {
            MOUSEINPUT mouseinput = new MOUSEINPUT();

            mouseinput.X     = x * (65535 / Screen.PrimaryScreen.Bounds.Width);
            mouseinput.Y     = y * (65535 / Screen.PrimaryScreen.Bounds.Height);
            mouseinput.Flags = (uint)(MouseFlag.LEFTDOWN | MouseFlag.MOVE | MouseFlag.ABSOLUTE);
            var click = new INPUT();

            click.Type       = (UInt32)InputType.MOUSE;
            click.Data.Mouse = mouseinput;
            INPUT[] inputList = new INPUT[1];
            inputList[0] = click;
            var numberOfSuccessfulSimulatedInputs = InputSimulator.SendInput(1, inputList, Marshal.SizeOf(typeof(INPUT)));

            if (numberOfSuccessfulSimulatedInputs == 0)
            {
                throw new Exception("Mouse Click Failed");
            }
        }