I need to write an app that clicks on windows.
How can I send a left button click to some screen x/y coordinate where a window is located?
I need to write an app that clicks on windows.
How can I send a left button click to some screen x/y coordinate where a window is located?
Use the SendInput() function:
INPUT Inputs[3] = {0};
Inputs[0].type = INPUT_MOUSE;
Inputs[0].mi.dx = ...; // desired X coordinate
Inputs[0].mi.dy = ...; // desired Y coordinate
Inputs[0].mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE;
Inputs[1].type = INPUT_MOUSE;
Inputs[1].mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
Inputs[2].type = INPUT_MOUSE;
Inputs[2].mi.dwFlags = MOUSEEVENTF_LEFTUP;
SendInput(3, Inputs, sizeof(INPUT));
Be sure to read the comments in the MOUSEINPUT
documentation regarding how to specify dx
and dy
correctly when using MOUSEEVENTF_ABSOLUTE
in a multi-monitor environment.
You can use mouse_event function to click on (x,y):
mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0);