Detect if computer goes into "Sleep Mode"?

Hey everyone, I was unable to find an answer to this. Is there a way to detect if the user’s computer goes into “Sleep Mode”? I believe on Mac’s its called Power Saving Mode? I’m working on an online game and would like to detect this and have the player automatically disconnect instead of waiting for a timeout.

I’m pretty new to Unity, so I don’t know how well this will integrate with the scripting system… but assuming you’re working on win32:

  • Add a reference to WindowsBase
  • Add event handler to SystemEvents.PowerModeChanged, function prototype is : ( object sender, PowerModeChangedEventArgs e )
  • You can detect a ‘suspend’ event by checking the PowerModes parameter

Hope that helps!

Awesome, thanks for the tip Capoeiraolly, I’ll have to look into this. Not sure if this would work in the web player or not, I’ll have to try it. Also, even if it does work I would need to detect if the person is either on Mac or Win and check for the same thing. What a headache :-\

Hmmm I can’t seem to get this to work . . . heres the code im using: