开发者

Alternative Input Device(Midi) doesn't prevent Screen Saver in Winforms application

开发者 https://www.devze.com 2022-12-24 13:02 出处:网络
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.

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 (i.e., key press). I don't want the screen saver or time lockou开发者_开发问答ts to occur if the MIDI device is actively being used.

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?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号