I have a piece of server-ish software written in Java to run on Windows and OS X. (It is not running on a server, but just a normal user's PC - something like a torrent client.) I would like the software to signal to the OS to keep the machine awake (prevent it from going into sleep mode) while it is active.
Of course I don't expect there to be a cross platform solution, but I would love to have some very minimal C programs/scripts that my app can spawn to inform the OS to stay awake.
Any ideas?
Go to Control Panel > Personalization > Change Screensaver. Next to On Resume, Display Logon Screen, uncheck the box. This prevents your system from sleeping.
Stop Screen from Turning Off in Windows 10Start by heading to Settings > System > Power & Sleep. Under the Power & Sleep section set the screen to turn off Never for both “On battery power” and “when plugged in.” If you are working on a desktop there will only be the option for when the PC is plugged in.
I use this code to keep my workstation from locking. It's currently only set to move the mouse once every minute, you could easily adjust it though.
It's a hack, not an elegant solution.
import java.awt.*; import java.util.*; public class Hal{ public static void main(String[] args) throws Exception{ Robot hal = new Robot(); Random random = new Random(); while(true){ hal.delay(1000 * 60); int x = random.nextInt() % 640; int y = random.nextInt() % 480; hal.mouseMove(x,y); } } }
On Windows, use the SystemParametersInfo function. It's a Swiss army-style function that lets you get/set all sorts of system settings.
To disable the screen shutting off, for instance:
SystemParametersInfo( SPI_SETPOWEROFFACTIVE, 0, NULL, 0 );
Just be sure to set it back when you're done...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With