#include <stdio.h>
#include <Windows.h>
#include <WinUser.h>
int main()
{
SetProcessDPIAware();
HDC monitor = GetDC(NULL);
POINT cursor;
COLORREF color;
while (TRUE) {
if (!GetCursorPos(&cursor)) {
puts("GetCursorPosError!");
exit(EXIT_FAILURE);
}
color = GetPixel(monitor, cursor.x, cursor.y);
if (GetRValue(color) == 75 && GetGValue(color) == 219 && GetBValue(color) == 106) {
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
}
printf("x: %ld y: %ld %d %d %dn", cursor.x, cursor.y, GetRValue(color), GetGValue(color), GetBValue(color));
}
ReleaseDC(NULL, monitor);
return 0;
}
Why, even when my cursor is stopped, the program displays a little bit different color values, at the same coordinate, of course, while the picture also does not move, which is also of course. The values what I get should be like (75, 219, 106) but it is very close to this like (70, 226, 90).
I tried changing the screen resolution, but it didn’t help.
And as you see I aslo tried to use SetProcessDPIAware() and that also didn’t help!