private static void SendInput(int x, int y, uint data, MouseEventFlags flags) { System.Diagnostics.Debug.WriteLine(" In Mouse SendInput "); // correct permissions ? // var permissions = new PermissionSet(PermissionState.Unrestricted); // permissions.Demand(); // System.Diagnostics.Debug.WriteLine(" USED COORDS 1 :: " + x + " " + y); // Check if we are trying to do an absolute move if (flags.HasFlag(MouseEventFlags.MOUSEEVENTF_ABSOLUTE)) { // Absolute position requires normalized coordinates NormalizeCoordinates(ref x, ref y); flags |= MouseEventFlags.MOUSEEVENTF_VIRTUALDESK; } // Build the mouse input object var mouseInput = new MOUSEINPUT { dx = x, dy = y, mouseData = data, dwExtraInfo = User32.GetMessageExtraInfo(), time = 0, dwFlags = flags }; // Build the input object var input = INPUT.MouseInput(mouseInput); // Send the command if (User32.SendInput(1, new[] { input }, INPUT.Size) == 0) { System.Diagnostics.Debug.WriteLine("error"); var errorCode = Marshal.GetLastWin32Error(); } else { System.Diagnostics.Debug.WriteLine("click " + mouseInput.dx); } }
private void SendInput(int x, int y, uint data, MouseEventFlags flags) { // Demand the correct permissions var permissions = new PermissionSet(PermissionState.Unrestricted); permissions.Demand(); // Check if we are trying to do an absolute move if (flags.HasFlag(MouseEventFlags.MOUSEEVENTF_ABSOLUTE)) { // Absolute position requires normalized coordinates NormalizeCoordinates(ref x, ref y); flags |= MouseEventFlags.MOUSEEVENTF_VIRTUALDESK; } // Build the mouse input object var mouseInput = new MOUSEINPUT { dx = x, dy = y, mouseData = data, dwExtraInfo = User32.GetMessageExtraInfo(), time = 0, dwFlags = flags }; // Build the input object var input = INPUT.MouseInput(mouseInput); // Send the command if (User32.SendInput(1, new[] { input }, INPUT.Size) == 0) { // An error occured var errorCode = Marshal.GetLastWin32Error(); return; } }