5

I am working on a web application that needs to be active on the monitor sometimes for hours without anyone touch the computer.

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. I found nothing, unfortunately.

I'm sorry for the too general question but I'm pretty helpless with this subject

Tomer Gal
  • 933
  • 12
  • 21
  • 4
    I am pretty sure, you can't do anything like that. At least via JS or Flash. – Kai Mattern Sep 09 '12 at 18:50
  • You should remove the javascript tag, there's no way you can do it with javascript... – Dmitry Pashkevich Sep 09 '12 at 18:51
  • You could do it, if you dispatch custom mousemove events, but this is a really dirty hack. – Manuel Leuenberger Sep 09 '12 at 18:53
  • 2
    Imagine if it was easily posible to do this. Websites would take over your mouse cursor and force you to click likes, accept the running of downloaded files, etc. fortunately using JS or Flash you cannot do this. – Loktar Sep 09 '12 at 18:57
  • Could you use http://stackoverflow.com/a/2322775/846476. If you move the mouse/cursor about then you might be able stop it from sleeping or getting the screensave started. It's a bit of a hack though so Im not sure it would work – RNJ Sep 09 '12 at 18:57
  • *"I'm sorry for the too general question.."* ..what 'question'? – Andrew Thompson Sep 10 '12 at 01:56

1 Answers1

1

I've written the Java applet for you. It will move the mouse cursor one pixel to the right and back every 59 seconds, effectively preventing the screen saver from kicking in.

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

}
Community
  • 1
  • 1
Petr Janeček
  • 37,768
  • 12
  • 121
  • 145