No amigo , aun así se me va mueve el cursor mira te paso el codigo entero.
mouse_event(MOUSEEVENTF_LEFTDOWN, 1290, 317, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 1290, 317, 0, 0);
1) Imagino que esas coordenadas las asignaste simplemente por probar, pero por si no es así lo comentaré de todas formas:
Le estás pasando unas coordenadas fijas, no las coordenadas actuales de tu mouse como te indiqué.
2) Si leyeras la documentación del método, la cual te he mostrado 3 o 4 veces ya, verías que los parámetros '
dw' y '
dy' actuan como coordenadas
RELATIVAS (es decir, moverse a un offset) a menos que especifiques el flag '
MOUSEEVENTF_ABSOLUTE' en el primer parámetro para que actuen como coordenadas absolutas.
dx & dy:
The mouse's absolute position along the x-axis or its amount of motion since the last mouse event was generated, depending on the setting of MOUSEEVENTF_ABSOLUTE. Absolute data is specified as the mouse's actual x-coordinate; relative data is specified as the number of mickeys moved. A mickey is the amount that a mouse has to move for it to report that it has moved.
dwflags:
· MOUSEEVENTF_ABSOLUTE
The dx and dy parameters contain normalized absolute coordinates. If not set, those parameters contain relative data: the change in position since the last reported position. This flag can be set, or not set, regardless of what kind of mouse or mouse-like device, if any, is connected to the system. For further information about relative mouse motion, see the following Remarks section.
Así que debes combinar los flags:
mouse_event(MOUSEEVENTF_LEFTUP | MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, , , ,)
EDITO:También dice:
If MOUSEEVENTF_ABSOLUTE value is specified, dx and dy contain normalized absolute coordinates between 0 and 65,535. The event procedure maps these coordinates onto the display surface. Coordinate (0,0) maps onto the upper-left corner of the display surface, (65535,65535) maps onto the lower-right corner.
Así pues, además de combinar los flags debes hacer una operación aritmética para ajustar las coordenadas:
VB.NET
Dim PosX As Integer = ((Cursor.Position.X * 65535I) / Screen.PrimaryScreen.Bounds.Width)
Dim PosY As Integer = ((Cursor.Position.Y * 65535I) / Screen.PrimaryScreen.Bounds.Height)
mouse_event(MouseEventFlags.ABSOLUTE Or MouseEventFlags.MOVE Or MouseEventFlags.LEFTDOWN Or MouseEventFlags.LEFTUP,
PosX, PosY, Nothing, Nothing)
C#:
int PosX = ((Cursor.Position.X * 65535) / Screen.PrimaryScreen.Bounds.Width);
int PosY = ((Cursor.Position.Y * 65535) / Screen.PrimaryScreen.Bounds.Height);
mouse_event(MouseEventFlags.ABSOLUTE | MouseEventFlags.MOVE | MouseEventFlags.LEFTDOWN | MouseEventFlags.LEFTUP, PosX, PosY, null, null);
//=======================================================
//Service provided by Telerik (www.telerik.com)
//Conversion powered by NRefactory.
//Twitter: @telerik
//Facebook: facebook.com/telerik
//=======================================================