How do I turn the monitor on and off in a Java application?
•
Java
How do I turn the monitor on and off in a Java application?
If you want to know why, this is a self-service terminal style application. It would be great to turn off the monitor at night Yes, you can do this in the screen saver settings of the machine, but it would be great to do this programmatically and avoid having to configure on each computer
Solution
Assuming that you deploy Java applications on windows, you can use this win32API function:
// turn off monitor SendMessage(HWND_BROADCAST,WM_SYSCOMMAND,SC_MONITORPOWER,(LPARAM) 2); // turn on monitor SendMessage(HWND_BROADCAST,(LPARAM) -1);
Then you write a small c-jni wrapper to the function calling the mentioned SendMessage, and use a small wrapper to close the monitor from Java
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码