1

I'm trying to write a script for SecureCRT in VBScript that sends keystrokes to automate some of my more repetitive tasks for me. Normally, all I have to do is press a couple of keys, but I'm trying to have a script press them for me.

The issue is that no matter how long I set the screen to wait for using crt.Sleep, it seems to do just wait, then press all of the keys at light speed.

In essence, my code looks like this:

crt.Screen.SendKeys "{TAB}"
crt.Sleep 10
crt.Screen.SendKeys "{TAB}"
crt.Sleep 10
crt.Screen.SendKeys "f"
crt.Sleep 10
crt.Screen.SendKeys "p"
crt.Sleep 10
crt.Screen.SendKeys "p"
crt.Sleep 10
crt.Screen.SendKeys "r"
crt.Sleep 10
crt.Screen.SendKeys "{F10}"
crt.Sleep 10
crt.Screen.SendKeys "{ENTER}"
crt.Sleep 250
crt.Screen.SendKeys "v"
crt.Sleep 10
crt.Screen.SendKeys "{F10}"
crt.Sleep 10
crt.Screen.SendKeys "{ENTER}"
crt.Sleep 250

(It's gross, I know—I originally had a function written to get rid of all the repetition, but I lost some of my progress)

ND523
  • 159
  • 8
  • Does this answer your question? [How to set delay in vbscript](https://stackoverflow.com/questions/1729075/how-to-set-delay-in-vbscript) – user692942 Apr 13 '21 at 00:12

1 Answers1

0

I often use the following function to add pause time. I am not sure how "crt.Sleep 10" works but this may work better for you.

Function Pause(PauseTime)       
Dim Start = Timer
    Do While Timer < Start + PauseTime
        'Pause
    Loop
End Function
Moir
  • 379
  • 4
  • 14
  • The problem with this approach is it is very CPU intensive because the loop is running as fast as the CPU can process it and checking each iteration whether the exit condition has been met. It also doesn’t hand off to the OS like `DoEvents` in VBA so it can lock-up your entire system if used for extended periods. [Better approaches](https://stackoverflow.com/a/14838808/692942) are provided in the duplicate question from 10 years ago that use something like running `ping -n 1 -w numberofms` to simulate the milliseconds delay. – user692942 Apr 13 '21 at 00:26