Is it possible to detect if player has turned displays on or off?

I am trying to write a script that will detect whether the player’s display is powered on or off, and if it has been turned off during gameplay.

Does anyone know of a way to do this accurately?

So far have used Unity’s Display.displays and Display.active but that does not give accurate information on whether a display has been turned on or off, only how many monitors are active for the game once they have been activated with Display.displays[×].Activate(). Also have tried a WMI solution posted on stack overflow Here using WmiMonitorBasicDisplayParams to test on Windows without accurate results. I have looked into using the Windows GetDevicePowerState, but the documentation declares that this function cannot be used to query the power state of a display device. and I have not been able to find a solution so far. Thank you for any help, please let me know if additional information is needed.

While not being fully what you want, you can probably see when a user enters and exits the game (goes to home and returns etc). Maybe this also works for screen off and on?

There’s two parts here:

  1. whatever whacky Windows stuff you have to query to know this information accurately

  2. wrapping that call and returning the result to Unity correctly.

Since #2 doesn’t matter if #1 doesn’t work, your first task is to contrive the simplest test (such as a Win32 console app) that hits this API, and test and qualify that until you are absolutely 100% confident that it works.

Step #1 is a Windows thing entirely, nothing whatsoever to do with Unity or this forum.

Once you have Step #1 working, then wrapping it as a native Unity plugin and returning it becomes a simple exercise of writing a native plugin, for which there are many tutorials and example codelets all over the interwebs.

Thank you for the suggestion, but I do need to know about the external display device specifically in this instance : )

Thanks Kurt, sounds like I will have to mess around with this a bit more and see if I can find a way to wrap some better native code!

Just want to give this issue a bump up, still looking for a solid solution