SendMessage/SC_MONITORPOWER won't turn monitor ON when running Windows 8

前端 未结 4 1087
死守一世寂寞
死守一世寂寞 2020-12-03 14:22

I turn my monitors on and off by using the following code:

[DllImport(\"user32.dll\")]
static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam,          


        
相关标签:
4条回答
  • 2020-12-03 14:40

    I had the same idea for this issue Just Changed the dear earlypearl's solution a wee bit and tested it on windows XP, 7, 8, Server 2008 and all worked perfectly.

    mouse_event(MOUSEEVENTF_MOVE, 0, 1, 0, UIntPtr.Zero);
    

    it does not need to be called twice.

    0 讨论(0)
  • 2020-12-03 14:45

    I had the same problem, the solution I found is to move the mouse :

    mouse_event(MOUSEEVENTF_MOVE, 0, 1, 0, NULL);
    Sleep(40);
    mouse_event(MOUSEEVENTF_MOVE, 0, -1, 0, NULL);
    

    It will wake the monitor on. Earlypearl

    0 讨论(0)
  • 2020-12-03 14:54

    I have found out this trick to work on windows 8.1

    Turn them off

    SendMessage(f.Handle, WM_SYSCOMMAND, (IntPtr)SC_MONITORPOWER, (IntPtr)MonitorShutoff);
    

    Turn them on

    SendMessage(f.Handle, WM_SYSCOMMAND, (IntPtr)SC_MONITORPOWER, (IntPtr)1);
    

    According to MSN, "1" is to switch monitor to "Low Power" but it does the trick. The screen will not turn off anymore.

    0 讨论(0)
  • 2020-12-03 14:56

    Here's Earlypearl's answer with the needed includes:

    [DllImport("user32.dll")]
    static extern void mouse_event(Int32 dwFlags, Int32 dx, Int32 dy, Int32 dwData, UIntPtr dwExtraInfo);
    
    private const int MOUSEEVENTF_MOVE = 0x0001;
    
    private void Wake(){
        mouse_event(MOUSEEVENTF_MOVE, 0, 1, 0, UIntPtr.Zero);
        Sleep(40);
        mouse_event(MOUSEEVENTF_MOVE, 0, -1, 0, UIntPtr.Zero);
    }
    
    0 讨论(0)
提交回复
热议问题