views:

85

answers:

2

I have developed a c# winforms application whereby the user is providing input via a midi connected device. The user will go for long periods without using the keyboard or mouse.

When I receive a midi message is there anything I can do to "tell" the system that this counts as user activity (ie key press). I don't want the screen saver or time lockouts to occur, if they are actively using the midi device.

I think my request is different than other requests I've seen because they want to disable screen savers for the life of their application whereby I just want midi input I receive to count as user interactivity.

Is there something I can call when I receive midi input to signify to the system user activity?

+1  A: 

Here's a CodeProject project that appears to do this:

http://www.codeproject.com/KB/cs/ScreenSaverControl.aspx

Looks like you can just call his SetScreenSaverTimeout(GetScreenSaverTimeout()) method every time you receive MIDI input.

MusiGenesis
@sean e: the call appears to both set the idle time *and* reset the idle time timer to that amount (just *as if* the user moved the mouse or typed on the keyboard). In any case, not worthy of a down-vote, hmm?
MusiGenesis
If that's the case, then he should: SetScreenSaverTimeout(GetScreenSaverTimeout()).Edit the answer and then I can change my vote.
sean e
@sean e: good suggestion. I updated my answer accordingly.
MusiGenesis
A: 

Windows sends out a message to each window before activating the screen saver or monitor power saver, all you need to do to prevent the screen from changing is to swallow these messages.

const int WM_SYSCOMMAND = 0x0112, SC_SCREENSAVE = 0xF140, SC_MONITORPOWER = 0xF170;
protected override void WndProc(ref Message m)
{
    if( m.Msg == WM_SYSCOMMAND ) //Intercept System Command
    {
        if( m.WParam.ToInt32() == SC_SCREENSAVE || m.WParam.ToInt32() == SC_MONITORPOWER )
        { 
            //Intercept ScreenSaver and Monitor Power Messages
            //MessageBox.Show("Reached SC/PowerCondition");
            return; // 
        }
    }   
    base.WndProc(ref m);
}

The sample code, along with further reading, is from this developer fusion thread.

Guildencrantz
From http://msdn.microsoft.com/en-us/library/cc144066%28VS.85%29.aspx : "Windows Vista and later: If password protection is enabled by policy, the screen saver is started regardless of what an application does with the SC_SCREENSAVE notification."
sean e