I’m trying to make a click at desktop through code, so I did that:
public static void MouseLeftClick(Point pos)
{
System.Windows.Forms.Cursor.Position = pos;
mouse_event(MOUSEEVENTF_LEFTDOWN, pos.X, pos.Y, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, pos.X, pos.Y, 0, 0);
}
I realize that it only works if I add the System.Windows.Forms.Cursor.Position = pos;
Why? mouse_event x,y parameters are useless?
Have you read the description of the
mouse_eventfunction?If for instance only
RIGHTDOWNis used, X and Y parameters don’t represent the coordinates where the mouse is set..Here’s how you could deal with
mouse_event:Of course, setting the cursor position is much more simple than using
mouse_eventto tell that your mouse has moved.Btw, this function has been superseded. Use
SendInputinstead.