7

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'.

fabsenet
  • 372
  • 2
  • 15

3 Answers3

4

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
Daniel Georgiev
  • 1,292
  • 16
  • 14
4

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;
    }
}
Evgeniy Vaganov
  • 345
  • 5
  • 6
0

I think I found the registry entry that reflects the current night light status.

[HKEY_CURRENT_USER\Control Panel\Quick Actions\Control Center\QuickActionsStateCapture]
"Toggles"="Toggles,...,Microsoft.QuickAction.BlueLightReduction:true,..."

Although it is not very reliable because I think it requires that this particular toggle should be visible...

Joe Mayo
  • 7,501
  • 7
  • 41
  • 60