I'm doing a program that reads a range of pixels and if find the red color, do a click with left mouse button, but it is too slow, like if the red dot shows up on the range, it takes 2 seconds or more to click.
This is a representation of the problem:
So if some red dot cross the green line, click with left mouse button. The green line do not exist, I drew it just to make it clearer.
Can someone propose a solution to read this interval in milliseconds? I think that the problem is to use a for loop to check the pixel colors.
I tried to use the solution proposed in the topic "Get Pixel color fastest way?" but this made the computer very slow and did not work. (I made some adjustments to adapt the solution to my problem). Also, because my problem is much simpler, I think there is a simpler solution than the one in the other topic, which is more complex and did not work for me.
This is my code:
int main()
{
HDC dc = GetDC(NULL);
POINT pt;
int x = 150;
while (1) {
for (int y = 205; y >= 0; y--) {
dc = GetDC(NULL);
COLORREF color = GetPixel(dc, x, y);
// the red color has value = 220
if (color == 220) {
GetCursorPos(&pt);
mouse_event(MOUSEEVENTF_LEFTDOWN, pt.x, pt.y, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, pt.x, pt.y, 0, 0);
}
}
}
ReleaseDC(NULL, dc);
}