如何让机器保持清醒?

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);
        }
    }
}

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

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)