Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you keep the machine awake?

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?

like image 391
Frank Krueger Avatar asked Sep 09 '08 20:09

Frank Krueger


People also ask

How do I keep my computer active while away?

Go to Control Panel > Personalization > Change Screensaver. Next to On Resume, Display Logon Screen, uncheck the box. This prevents your system from sleeping.

How do I make my System always active?

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.


2 Answers

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);         }     } } 
like image 96
ScArcher2 Avatar answered Oct 02 '22 14:10

ScArcher2


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...

like image 28
Matt Dillard Avatar answered Oct 02 '22 16:10

Matt Dillard