How do you turn on and off a monitor from within a Java application?

后端 未结 4 863
长发绾君心
长发绾君心 2020-12-06 03:12

How do you turn on and off a monitor from within a Java application?

In case you\'re wondering why, this is a kiosk style application where it would be great to turn

相关标签:
4条回答
  • 2020-12-06 03:56

    Assuming you deploy your Java Applications on Windows, you can use this WIN32API functions:

    // turn off monitor
    SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM) 2); 
    
    // turn on monitor
    SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM) -1);    
    

    Then you write a little C-JNI wrapper to functions that call the mentioned SendMessage and use the little wrapper to turn off the monitor from Java.

    0 讨论(0)
  • 2020-12-06 04:01

    While you can query the monitor configurations with Java, there is no way to turn the monitors on and off programatically without using JNI.

    0 讨论(0)
  • 2020-12-06 04:01

    I have seen this exe named nircmd on the net. It is a freeware and can be used on by anyone.It has a built in function for doing this.

    nircmd.exe monitor off 
    

    A detailed help is also found in the website. Just use it in your program and call it using

    Runtime.getRuntime().exec(this.getClass().getResource("nircmd.exe").getPath());
    

    or put it to the windows directory and run it from there.

    0 讨论(0)
  • 2020-12-06 04:08

    You can open a full screen swing window, make it completely black, so the monitor, as far as observable behavior is concerned, is turned off.

    0 讨论(0)
提交回复
热议问题