如何让机器保持清醒?

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 implement RecyclerView with section header depending on category?(如何根据类别实现带有节标题的 RecyclerView?)
How to generate JNI header file in Eclipse(如何在 Eclipse 中生成 JNI 头文件)
Setting a custom HTTP header dynamically with Spring-WS client(使用 Spring-WS 客户端动态设置自定义 HTTP 标头)
Could you technically call the string[] anything in the main method?(从技术上讲,您可以在 main 方法中调用 string[] 吗?)
What is the proper way of setting headers in a URLConnection?(在 URLConnection 中设置标头的正确方法是什么?)
How to overwrite http-header quot;Hostquot; in a HttpURLConnection?(如何覆盖 http-header “主机在 HttpURLConnection 中?)