你怎么让机器保持清醒? [英] How do you keep the machine awake?

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

问题描述

我有一个用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程序/脚本,我的应用程序可以产生,以通知操作系统保持清醒。

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.

这是一个黑客,而不是一个优雅的解决方案。

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

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆