4

I am currently trying to make an autotyper in VBS and I cannot figure out how to easily input what is to be typed. Right now, this is what my code has to look like:

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.AppActivate "notepad"
WScript.sleep 10000
WshShell.SendKeys "H"
WScript.Sleep 100
WshShell.SendKeys "e"
WScript.Sleep 100
WshShell.SendKeys "l"
WScript.Sleep 100
WshShell.SendKeys "l"
WScript.Sleep 100
WshShell.SendKeys "o"

But I really want my code to have all the text that will be auto-typed in just one line instead of me having to repeat the SendKeys for every letter.

  • 1
    To clarify, the OP's code works. They just want a more efficient way of providing the input instead of specifying individual `SendKeys()` method calls. – user692942 Aug 29 '18 at 12:57

2 Answers2

5

I made for you a little example that can type letter by letter as a Typewriter.

Hope this what you are looking for !

strText="Hello ! How are you mate ? Hope that everything is OK !" & vbCrlf &_
"This vbscript is made by Hackoo !" 
Call AutoTypeWriter(strText)
'------------------------------------------
Sub AutoTypeWriter(strText)
  intPause = 150
  Set Ws = CreateObject("WScript.Shell")
  'To start Notepad maximized
  Ws.Run "Notepad",3
  WScript.Sleep 1000
  intTextLen = Len(strText)
  For x = 1 to intTextLen
    strTempText = Mid(strText,x,1)
    Ws.Sendkeys strTempText
    WScript.Sleep intPause
  Next
End Sub
'------------------------------------------

enter image description here

Hackoo
  • 18,337
  • 3
  • 40
  • 70
0

This works for me .. here

strtext = inputbox ("Message (Auto-typer made/coded by bolts)")
strtimes = inputbox ("Message Amount (Amount of messages)")

If not isnumeric (strtimes) then
msgbox "Hint: Use numbers."
wscript.quit
End If
strspeed = inputbox ("Message Speed (How many per second. 1000 = 1 message per second, 100 = 10 messages per second)")

If not isnumeric (strspeed) then
msgbox "Hint: Use numbers."
wscript.quit
End If
strtimeneed = inputbox ("How long before the typing starts. (Seconds)")

If not isnumeric (strtimeneed) then
msgbox "Hint: Use numbers."
wscript.quit
End If
strtimeneed2 = strtimeneed * 1000
do
msgbox "You have " & strtimeneed & " seconds to get to your text area where you are going to type."
wscript.sleep strtimeneed2
shell.sendkeys ("" & "{enter}")
for i=0 to strtimes
shell.sendkeys (strtext & "{enter}")
wscript.sleep strspeed
Next
shell.sendkeys ("" & "{enter}")
wscript.sleep strspeed * strtimes / 10
returnvalue=MsgBox ("Want to type again with the same message, ammount, speed and time?",36)
If returnvalue=6 Then
msgbox "Ok typing will start again in a few seconds."
End If
If returnvalue=7 Then
msgbox "Bolts' lazy auto-typing program is going to sleep."
wscript.quit
End IF
loop
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 12 '22 at 20:47