How do I make a batch file that will automatically press a key?

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.

2

2 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.

  1. Use the SendKeys method (i.e. WSH.SendKeys("{f2}");) to click a key in Windows Explorer.
  2. Choose a key that will not cause an adverse action.
  3. 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:

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like