Search code examples
pythonwmi

How to get the screen brightness in python on a windows laptop?


I'm creating a program to set my keyboard and mouse brightness according to my screen brightness. The issue is that I don't know how to get my screen brightness (I know that i can set my screen brightness with this line: wmi.WMI(namespace='wmi').WmiMonitorBrightnessMethods()[0].WmiSetBrightness(desired_brightness, 0))

But I want to know how to get the brightness instead of changing it. Maybe I can use one of the windows dlls with ctypes or maybe I can do this with wmi but i don't really understand how it works.

If you have any idea on how to do that, please tell me.


Solution

  • Try WmiMonitorBrightness()[0].Like:

    import wmi
    
    print(wmi.WMI(namespace='wmi').WmiMonitorBrightness()[0])
    

    This has the same result with my device:

    enter image description here