Search code examples
pythonpyautogui

PyAutoGui Nan NaN NaN


pyautogui.displayMousePosition() displays 848 Y: 853 RGB: (NaN, NaN, NaN)

I am not sure why it will not pick up RGB colors. thanks


Solution

  • Make sure that sys.platform == "darwin" returns False. As you can see in PyAutoGui's python file:

    if not onScreen(x - xOffset, y - yOffset) or sys.platform == "darwin":
        # Pixel color can only be found for the primary monitor, and also not on mac due to the screenshot having the mouse cursor in the way.
        pixelColor = ("NaN", "NaN", "NaN")
    

    if sys.platform returns "darwin", it's normal for you to get RGB: (NaN, NaN, NaN) as result.

    To fix this problem, you can simply do:

    import sys
    
    sys.platform = '_' # sys.platform is no longer "darwin"
    pyautogui.displayMousePosition()