Page 1 of 1

getPixel() and dual monitors

Posted: Fri Apr 06, 2012 4:25 pm
by vIndie
It doesn't appear that getPixel works correctly on the secondary monitor in dual monitor setup, it returns 255,255,255 regardless of the actual color of the pixel.

Here is the code I used to test.

Code: Select all

function main()
	while(1) do
		hwnd = foregroundWindow();
		if (hwnd ~= 0) then
			hdc = openDC(hwnd);
			if (hdc) then
				x,y = mouseGetPos();
				-- printf("mouse_x: %d, mouse_y: %d", x, y);
				r,g,b = getPixel(hdc, x, y);
				printf("(%d, %d) RGB: %d, %d, %d\n", x,y, r, g, b);
				closeDC(hdc);
			end
		end
		stopPE();
	end
end

startMacro(main);

Re: getPixel() and dual monitors

Posted: Sat Apr 07, 2012 2:37 pm
by Administrator
Well, first problem is that getPixel expects client coordinates, not screen coordinates. That means that 0,0 is the top-left of the window, not the top-left of your screen. So, if you had dual monitors running 1920x1080 resolution and you had your mouse positioned at, say, 2000x20 (near the top-left corner of your second screen), that would be beyond the client area of the window, and hence be an invalid position to read pixel information from.