0

I've tried to make it myself, but it didn't work, as I'm not experienced enough with .bat to get it working.

So what I need is bascily a .bat file which I only need to click once and it will "simulate" me clicking the key 'Enter' every 10800 seconds (3 hours) in a loop, so that it doesn't ever stop clicking the key 'Enter' with a loop time of 10800 seconds, would someone help me out please! :)

  • 2
    "every three hours" surely calls for a scheduled task... – Stephan Jun 05 '17 at 21:02
  • 1
    Batch files cannot do such things. Perhaps you are interested in [AutoIt](http://autoitscript.com) or [AutoHotkey](http://autohotkey.com)? – aschipfl Jun 05 '17 at 21:37
  • Haha! Sure, Windows can do this natively... You don't need to install some other tool – Tim Jun 05 '17 at 21:49
  • Possible Duplicate. https://stackoverflow.com/questions/17038282/press-keyboard-keys-using-a-batch-file – Gerhard Jun 06 '17 at 06:17
  • 2
    Possible duplicate of [Press Keyboard keys using a batch file](https://stackoverflow.com/questions/17038282/press-keyboard-keys-using-a-batch-file) – Gerhard Jun 06 '17 at 06:54

1 Answers1

1

You can do this with VBScript and the WScript host:

Save this as "press_enter.vbs" and run it from the CLI with "wscript press_enter.vbs"

Dim WshShell, FSO, secs

Set WshShell = WScript.CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")

secs = 10800
kill_file = "C:\Users\Public\Documents\kill_switch.txt"

Do While true
    WScript.Sleep(secs * 1000) ' this is in milliseconds, multiple by 1000
    WshShell.SendKeys "{ENTER}"
    if FSO.FileExists(kill_file) then exit do
Loop

As you probably guessed, the program runs forever until it detects the existence of the file "C:\Users\Public\Documents\kill_switch.txt"

You can also kill the program by opening Task Manager and killing the "Microsoft Windows Based Script Host" which will be listed under the "Background processes" section...

Remember that if you stop the application with the "kill_switch.txt" file, you will need to remove it before you start the application again. Perhaps it is best just to kill it with Task Manager...

Tim
  • 2,139
  • 13
  • 18
  • Also... you may want to look into WshShell a bit more. You can do some really neat stuff with it. I have used it to open a series of applications and input data automatically. This is useful for legacy applications which do not provide an API. – Tim Jun 05 '17 at 20:56