如何让机器保持清醒?

How do you keep the machine awake?(如何让机器保持清醒?)

本文介绍了如何让机器保持清醒?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用 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);
        }
    }
}

这篇关于如何让机器保持清醒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何让机器保持清醒?

基础教程推荐