I want to get the RGB value of the current mouse position on my macbook screen. Right now it is not showing correct: When I hover my mouse over a black image the RGB values don't go near (0, 0, 0) it stays like (181, 201, 233). When I put my mouse cursor on a playing YT video the RGB values do not change. Only When I move my mouse the RGB values change, but not accordingly. I have tried these functions in IDLE/new file:
1.
pyautogui.displayMousePosition() #output: X: 183 Y: 291 RGB: (174, 188, 211)
2.
posXY = pyautogui.position()
print(pyautogui.pixel(posXY[0], posXY[1])) #output: RGB(red=200, green=212, blue=224)
3.
im = pyautogui.screenshot()
pxRGB = im.getpixel((PosXY[0], PosXY[1])) #output: (181, 203, 229, 255)
4.
pxRGB = ImageGrab.grab().getpixel((PosXY[0], PosXY[1])) #output: (167, 192, 225, 255)
All of these ouputs were rong, But what did work was downloading a black-white image from internet opening it and getting the pixel value from it:
im = Image.open("black-white.jpg").convert('RGB')
px = im.getpixel((PosXY[0], PosXY[1]))
print(px) #output (0, 0, 0) and (255, 255, 255) working!
now I tried to do the same with a screenshot from my laptop (in code and out code) and using that img but that still didn't gave me correct RGB values. (even if the mouse position was incorrect I couldn't find a point darker then like (50, 46, 76) while there were plenty of them on the SC)
Any help would really be appreciated!
extra information: Macbook pro Catalina 10.15.7 I tried it first on Python 3.8 and then 3.9 The mouse positions were showed correct, left top (0, 0) and right bottom (1679, 1049). Pyautogui.displayMousePosition() is giving on my windows 7/10 laptops correct RGB values. I see that the Screenshots that were made with pyautogui.screenshot() only show my backbroundimg and not open windows like internet or some files. But 'not in code' Sc are looking normal they have though not .png assigned to them by default just empty: examplescreenshot12-23-3 Also all the code that I could find online didn't work for me. To be able to see any RGB values from the function I had to import first sys and then setting sys.platform = darwin to sys.platform = '_' I'm not working in a virtual environment and not experienced in python. I do not really care how long it will take to get the pixel RGB value. Changing backgroundImg on my macbook does result in different outputs but still not correct.