I want to create a simple batch file that will press a key automatically so that my computer won't automatically shut down after a long time of being away from the keyboard. Is that possible?
My operating system is Windows Vista.
22 Answers
First, I'd recommend going to the Power control panel and just setting your computer to never sleep or shutdown after an inactivity period.
If you still want to achieve what you specified, you can easily use a Windows Scripting Host (WSH) script, written in either JavaScript or VBScript.
- Use the SendKeys method (i.e.
WSH.SendKeys("{f2}");) to click a key in Windows Explorer. - Choose a key that will not cause an adverse action.
- Use scheduler to run your script once in a while.
Rather than pressing keys, there are apps that will temporarily prevent your computer from going to sleep:
- Don't Sleep
- Insomnia
- Caffeine (actually, this one works by simulating key presses)