I have an app that sets a fullscreen frame but seems to minimize when the screensaver turns on. I want this app to be the only application that the users of the touchscreen kiosks can use so this is a problem. Is there anyway to prevent this?
-
1Which operating system do you use ? – Serafeim May 30 '11 at 15:30
-
1can't you just disable screensaver? – Denis Tulskiy May 30 '11 at 15:56
-
These machines are left on 24/7 and we'd prefer to not lose lifetime on 600$ touchscreens. – davidahines May 31 '11 at 19:52
-
This may be what you are looking for: http://stackoverflow.com/a/28375740/1686442 – Scott Wardlaw Feb 06 '15 at 22:18
3 Answers
The internet says that the cross-platform way to achieve this is to schedule keyboard events with this code:
import java.awt.Robot;
public void disableScreenSaver() throws AWTException {
Robot r = new Robot();
r.waitForIdle();
r.keyPress(KeyEvent.VK_CONTROL);
r.keyRelease(KeyEvent.VK_CONTROL);
}
and to schedule it to run every couple of minutes (e.g. with thread.sleep();
). This way the screen-saver will not show up.
I have no idea, though, about a non-hackish, cross-platform solution, and I would be very happy to see one from someone who knows it :)

- 7,052
- 2
- 29
- 39
-
1Don't use `thread.sleep();` in one thread in a loop for this. Use a `ScheduledExecutorService` instead. – Simon Forsberg Mar 11 '14 at 08:34
Probably (haven't tried it !) you'll get your answer by combining the answers to these questions:
Calling Win32 API method from Java
Need to disable the screen saver / screen locking in Windows C#/.Net
Of course this works only in Windows that's why I asked you about your OS :)
Another way is to add a window listener and reset state when it's deactivated:
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowDeactivated(WindowEvent e) {
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
// or go to fullscreen mode here
}
});
But disabling screensaver might be the best thing to start with.

- 19,012
- 6
- 50
- 68