問題描述
我有一個用 Java 編寫的服務器式軟件,可以在 Windows 和 OS X 上運行.(它不是在服務器上運行,而只是在普通用戶的 PC 上運行 - 類似于 torrent 客戶端.)我想要軟件向操作系統發出信號以在機器處于活動狀態時保持機器喚醒(防止其進入睡眠模式).
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.
當然,我不希望有一個跨平臺的解決方案,但我希望有一些非常小的 C 程序/腳本,我的應用可以生成這些 C 程序/腳本來通知操作系統保持清醒.
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.
有什么想法嗎?
推薦答案
我使用此代碼來防止我的工作站鎖定.它目前只設置為每分鐘移動一次鼠標,但您可以輕松調整它.
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.
這是一個 hack,而不是一個優雅的解決方案.
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);
}
}
}
這篇關于如何讓機器保持清醒?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!