how to shutdown a system when it is not used. if a system is not used for a 2 minutes of time like not even used keyboard or mouse or any other applications in system. that system should be shut down. how to make this one possible.
-
Your definition of "not used" is too vague. There are gauranteed to be applications running on any given system 100% of the time it's running. Could you narrow that down at all? – CollinD Apr 27 '17 at 05:20
-
`System.exit(0);` – wylasr Apr 27 '17 at 05:20
-
3what type of `system` ? – Scary Wombat Apr 27 '17 at 05:23
1 Answers
The Process class allows you to run commands for windows/any OS from java below is snippet
Process proc = runtime.exec("shutdown -s");
System.exit(0);
Place the above code in your logic and rest how you want that to invoke depends on your logic the way you want.
Note : Here I am guessing by system you mean your OS. if you mean just application then just System.exit(0); would suffice.
EDIT :
As asked by OP to check the idle time, I think you need to implement event listeners mostly mouse and keyboard. Below are some helpful links to which will help you implement it in your program:
Java mouse motion anywhere on screen
How can I listen for key presses (within Java Swing) across all components?
Approach for above is have a timer just when you record an event from keyboard or mouse reset the timer else shutdown.
-
does not answer *like not even used keyboard or mouse or any other applications in system* – Scary Wombat Apr 27 '17 at 05:41
-
LOL After a short delay I can tell you that this does indeed work from windows as well. – Scary Wombat Apr 27 '17 at 06:04
-
@ScaryWombat edited the answer to check idle time while not using keyboard or mouse. – SiddP Apr 27 '17 at 06:12