Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get status of night light mode in Windows 10

I am using the desktop duplication api to grab the screen content and as it turns out, the new night light mode ('Nachtmodus' in German) is not applied in the grabbed screen content.

How do I read (if possible directly in c#) the night mode status (enabled, color shift amount)?

or

How can I tell Windows to give me the color shifted image using the desktop duplication api?

Basically, I want to know the state of what is configured inside these red boxes:

Night light settings (German)


Background: I am working on an ambilight implementation and if the night light mode is enabled, the color shift is not reflected in the LEDs around my screen and so the colors are off between screen content and 'around screen'.

like image 400
fabsenet Avatar asked Apr 11 '17 08:04

fabsenet


2 Answers

This method works for me in Windows 10 Version 2004

private static bool IsNightLightEnabled()
{
    const string BlueLightReductionStateKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\CloudStore\Store\DefaultAccount\Current\default$windows.data.bluelightreduction.bluelightreductionstate\windows.data.bluelightreduction.bluelightreductionstate";
    using (var key = Registry.CurrentUser.OpenSubKey(BlueLightReductionStateKey))
    {
        var data = key?.GetValue("Data");
        if (data is null)
            return false;
        var byteData = (byte[])data;
        return byteData.Length > 24 && byteData[23] == 0x10 && byteData[24] == 0x00;
    }
}
like image 196
Evgeniy Vaganov Avatar answered Sep 19 '22 08:09

Evgeniy Vaganov


You can check the output of

GetDeviceGammaRamp

Function from the Win API. Compare the output to Night Light ON and OFF and you should detect it.

Or you can try to monitor this Reg key for changes

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\CloudStore\Store\Cache\DefaultAccount\$$windows.data.bluelightreduction.settings\Current
like image 30
Daniel Georgiev Avatar answered Sep 20 '22 08:09

Daniel Georgiev