0

I just want my computer's screen not to turn off while a program is runnig. I know I can set it on my PC settings but I just want this app to do it.

Can anybody help me?

Thanks!

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • [This might help.](https://stackoverflow.com/questions/52874/how-do-you-keep-the-machine-awake) In any way you might have more chances of a good answer after you [read a little bit from the Help Center](https://stackoverflow.com/help/how-to-ask). – laancelot May 16 '20 at 15:17
  • no the question is fine like this if you don't know the first thing about doing what you are asking about. i'll look for a solution. – person the human Jun 04 '20 at 01:00

1 Answers1

0

I found the following code here

import java.awt.Robot;
import java.awt.MouseInfo;

long robotLastMove = 0;
Robot robot=null;

setup(){
                try{
                    robot = new Robot();
                }catch(Exception e){e.printStackTrace();}
}

draw(){
        long now = System.currentTimeMillis();
        if(robot!=null && now-robotLastMove>1000*60*15){
            //TODO: move back the mouse
            int x = MouseInfo.getPointerInfo().getLocation().x;
            int y = MouseInfo.getPointerInfo().getLocation().y;
            //robot.
            robot.mouseMove(x+2, y+2);
            robot.mouseMove(x, y);
            robotLastMove=now;
        }
}

This moves the mouse automatically when your PC tries to sleep, but only a little. If you save the code inside the draw function from the above code into a different function, you can call it in the the draw to make the code look better. Like this:

import java.awt.Robot;
import java.awt.MouseInfo;

long robotLastMove = 0;
Robot robot=null;

setup(){
                try{
                    robot = new Robot();
                }catch(Exception e){e.printStackTrace();}
}

void stayAwake(){
        long now = System.currentTimeMillis();
        if(robot!=null && now-robotLastMove>1000*60*15){
            //TODO: move back the mouse
            int x = MouseInfo.getPointerInfo().getLocation().x;
            int y = MouseInfo.getPointerInfo().getLocation().y;
            //robot.
            robot.mouseMove(x+2, y+2);
            robot.mouseMove(x, y);
            robotLastMove=now;
        }
}

void draw(){
    background(0);
    stayAwake();

    // the code you want to run without your pc falling asleep.
}

Good luck!

person the human
  • 345
  • 4
  • 15