"Dave" <dc*****@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
I did but no one answered my question. I think most people
misunderstood me.
When the machine is idle for 20 mins (or however long it is set in
Power Options) the monitor backlight turns off. The power button is
not pressed on the monitor. My application plays many different types
of media including movies and audio. But when they press a button to
make the monitor go to sleep (or the backlight turning off) everything
is paused. Now my problem is that when the mouse is moved or a key is
pressed the monitor automatically comes back on. I want to know when
this happens so that i can start the media files to play again.
Thanks again for the help.
I assume you are talking about power management features that are enabled on
your system.
While it's not possible to detect when the monitor is turned off due to
power management actions, it's quite possible to detect when a system enters
the 'suspend' state and returns from suspend state.
The following simple console sample shows you how you can use
System.Managent to watch these power status events.
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Management;
class Program {
public static void Main() {
Program we = new Program();
ManagementEventWatcher w= null;
WqlEventQuery q = new WqlEventQuery();;
ManagementOperationObserver observer = new ManagementOperationObserver();
// Bind to local machine
ManagementScope scope = new ManagementScope("root\\CIMV2");
try {
q.EventClassName = "Win32_PowerManagementEvent";
Console.WriteLine(q.QueryString);
w = new ManagementEventWatcher(scope, q);
w.EventArrived += new EventArrivedEventHandler(we.UsbEventArrived);
w.Start();
Console.ReadLine(); // block main thread for test purposes only
}
finally {
w.Stop();
}
}
public void UsbEventArrived(object sender, EventArrivedEventArgs e) {
//Get the Event object and display it
foreach(PropertyData pd in e.NewEvent.Properties) {
Console.WriteLine("\n================Power event===================");
Console.WriteLine("{0}", pd.Value); // possible values 4, 7, 10, 11, 18
see WMI SDK docs
}
}
}
Willy.