I need to press mouse left button in code.
I move the mouse using:
[DllImport("User32.dll")]
private static extern bool SetCursorPos(int X, int Y);
But I need a native (or not) method to perform a click in left button of the mouse.
It's a wpf application, however, when the mouse button is supposed to be pressed by the application, the mouse will be outside the wpf window (and the window will not have focus).
I ran into some codes like this:
MouseButtonEventArgs arg = new MouseButtonEventArgs(Mouse.PrimaryDevice, 0, MouseButton.Left) {
RoutedEvent = Button.MouseLeftButtonDownEvent
};
and then:
RaiseEvent(arg);
-or-
OnMouseLeftButtonDown(arg);
But they don't work. And I think it because these methods came from UIElement.
Maybe a dll import will do. I just don't know which.