Simulate Windows Function 'Turn Off Monitor after "X" amount of minutes' RRS feed

  • Question

  • I have a program that I would like to see if the mouse or keyboard has had inactivity for a certain amount of time then turn off the monitor. Unfortunately the way I set it up, when every i move the mouse through the screen it turns off the mouse with no delay.

    my code looks like this, and i am aware that the implementation is all wrong.

        Private Sub tmrScreen_Tick(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles tmrScreen.Tick  
            SendMessage(frmMain.Handle.ToInt32, WM_SYSCOMMAND, SC_MONITORPOWER, MON_OFF)  
        End Sub 
        Private Sub Mouse_Movement(ByVal sender As ObjectByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove  
            If (SendMessage(frmMain.Handle.ToInt32, WM_SYSCOMMAND, SC_MONITORPOWER, MON_OFF)) = False Then 
                tmrScreen.Enabled = False 
                tmrScreen.Enabled = True 
            End If 
        End Sub 
    Thursday, January 22, 2009 1:37 AM


  • You might think about P/Invoking the GetLastInputInfo API.

    Be sure to read the caveats in the documentation remarks:  http://msdn.microsoft.com/en-us/library/ms646302.aspx

    Your post does beg the question as to why you are just not using the Windows "Power Options" Control Panel to configure the system to turn off the monitor when idle.

    • Marked as answer by Riquel_Dong Wednesday, January 28, 2009 12:40 PM
    Thursday, January 22, 2009 2:02 AM