简体   繁体   English

通过网站禁用屏幕保护程序/睡眠模式

[英]Disable screen saver / sleep mode through a website

I am working on a web application that needs to be active on the monitor sometimes for hours without anyone touch the computer. 我正在开发一个需要在显示器上活动的Web应用程序,有时几个小时没有人触摸计算机。

The problem is that some computers have their screen saver, or worse - sleep mode while their inactive. 问题是有些计算机有屏幕保护程序,或者更糟 - 睡眠模式,而它们处于非活动状态。

I'm trying to think of a way to bypass it. 我试图想办法绕过它。 I searched for java applets or maybe a flash file that does only that. 我搜索了java applets或者只是那个闪存文件。 I found nothing, unfortunately. 不幸的是,我一无所获。

I'm sorry for the too general question but I'm pretty helpless with this subject 对于这个过于笼统的问题我很抱歉,但我对这个问题很无奈

I've written the Java applet for you. 我已经为你编写了Java applet。 It will move the mouse cursor one pixel to the right and back every 59 seconds, effectively preventing the screen saver from kicking in. 它会将鼠标光标每隔59秒向右移动一个像素,有效防止屏幕保护程序被踢入。

Note that because of security restrictions this applet will need to be signed and granted the createRobot permission to work on the client, otherwise it will fail to initialize the Robot class. 请注意, 由于安全限制,需要对此applet 进行签名授予createRobot权限以在客户端上工作,否则将无法初始化Robot类。 But that's a problem outside this question's scope. 但这是问题范围之外的问题。

import java.applet.Applet;
import java.awt.*;
import java.util.Timer;
import java.util.TimerTask;

/**
 * Moves the mouse cursor once in a minute to prevent the screen saver from
 * kicking in.
 */
public class ScreenSaverDisablerApplet extends Applet {

    private static final int PERIOD = 59;
    private Timer screenSaverDisabler;

    @Override
    public void start() {
        screenSaverDisabler = new Timer();
        screenSaverDisabler.scheduleAtFixedRate(new TimerTask() {
            Robot r = null;
            {
                try {
                    r = new Robot();
                } catch (AWTException headlessEnvironmentException) {
                    screenSaverDisabler.cancel();
                }
            }
            @Override
            public void run() {
                Point loc = MouseInfo.getPointerInfo().getLocation();
                r.mouseMove(loc.x + 1, loc.y);
                r.mouseMove(loc.x, loc.y);
            }
        }, 0, PERIOD*1000);
    }

    @Override
    public void stop() {
        screenSaverDisabler.cancel();
    }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM