Hack Forums
[Shell] [EPT] VBScript SendKeys Command Generator - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Shell] [EPT] VBScript SendKeys Command Generator (/showthread.php?tid=5605279)



[EPT] VBScript SendKeys Command Generator - Beigevenus - Apr 21, 2017


Introduction
As I sit here, listening to nightcore (Go ahead and judge me!) reading threads on the Subreddit LetsNotMeet, I realize... I gotta make another post!
This time I have decided to show off one of my useful batch files, the VBScript SendKeys Command Generator.

The Software
Actually this one is pretty useless, unless you need it for the exact scenario that I made it for. However, it's quite genius anyway! What it does, is; It asks for the word or phrase you want written out, asks for a timeout period in seconds, and generates a text file with the necessary commands to write it out in a smooth style with a VB script.
I've only used this once, however, it makes the process of making VBScript write out text in a smooth way much faster, trust me on this one.

The Source Code
As always, the source code is right here, and I would appreciate it if you didn't take credit for the code I've written, and instead wrote something on your own. Using it yourself, I have nothing against, though.


Code
@echo off
setlocal EnableDelayedExpansion
set num=0

REM User input
echo Enter string:
set /p str=:
echo.
echo Enter timeout amount:
set /p tm=:

REM Check string length
echo %str%> tempfile.txt
for %%? in (tempfile.txt) do ( set /A strlength=%%~z? - 2 )
del tempfile.txt

REM Loop 1*string length
:b
for /L %%A in (1,1,%strlength%) do (
    goto a
)
goto exit

:a
set res%num%="!str:~%num%,1!"
echo WshShell.SendKeys "!res%num%:~1,-1!">>Output.txt
echo WScript.Sleep %tm%>>Output.txt
set /a num+=1
set /a strlength-=1
goto b

:exit
exit


Using the File
To use it, simply just paste the source code into a text file and save it as a batch file (.bat).

QTDWBA (Questions That Definitely Will Be Asked)
Why would you ever make something this useless?
Well, I was working on a project quite a while ago, which required VBScript to write text in notepad by itself, and I wanted to make it look more "smooth" (And lazy as I am, I didn't want to write every line of code myself)

Why are you still here, Beigevenus? Haven't you given up on Batch yet?
I SHALL NEVER GIVE UP ON BATCH, AND YOU CAN'T STOP ME FROM MAKING MORE USELESS JUNK!!!



* - Hackoo - Apr 22, 2017

Hi ✌
Nice idea, but you missed up to create the shell object into the vbs file 🙃
Code
echo set WshShell=CreateObject("wscript.Shell"^)

So, your code can be tweaked like this one :
Code
@echo off
setlocal EnableDelayedExpansion
set num=0
set "Output=Output_%Random%.vbs"
echo set WshShell=CreateObject("wscript.Shell"^) >"%Output%"
REM User input
echo Enter string:
set /p str=:
echo.
echo Enter timeout amount:
set /p tm=:

REM Check string length
echo %str%> tempfile.txt
for %%? in (tempfile.txt) do ( set /A strlength=%%~z? - 2 )
del tempfile.txt

REM Loop 1*string length
:b
for /L %%A in (1,1,%strlength%) do (
    goto a
)
goto exit

:a
set res%num%="!str:~%num%,1!"
(
    echo WshShell.SendKeys "!res%num%:~1,-1!"
    echo WScript.Sleep %tm%
)>>"%Output%"
set /a num+=1
set /a strlength-=1
goto b

:exit
Rem open Notepad
Start "" Notepad
Rem and execute the vbscript inside the open notepad
Start "" "%Output%"
exit



* - Beigevenus - Apr 22, 2017

(Apr 22, 2017 12:52 AM)Hackoo Wrote:  Hi ✌
Nice idea, but you missed up to create the shell object into the vbs file 🙃
Code
echo set WshShell=CreateObject("wscript.Shell"^)

So, your code can be tweaked like this one :
Code
@echo off
setlocal EnableDelayedExpansion
set num=0
set "Output=Output_%Random%.vbs"
echo set WshShell=CreateObject("wscript.Shell"^) >"%Output%"
REM User input
echo Enter string:
set /p str=:
echo.
echo Enter timeout amount:
set /p tm=:

REM Check string length
echo %str%> tempfile.txt
for %%? in (tempfile.txt) do ( set /A strlength=%%~z? - 2 )
del tempfile.txt

REM Loop 1*string length
:b
for /L %%A in (1,1,%strlength%) do (
    goto a
)
goto exit

:a
set res%num%="!str:~%num%,1!"
(
    echo WshShell.SendKeys "!res%num%:~1,-1!"
    echo WScript.Sleep %tm%
)>>"%Output%"
set /a num+=1
set /a strlength-=1
goto b

:exit
Rem open Notepad
Start "" Notepad
Rem and execute the vbscript inside the open notepad
Start "" "%Output%"
exit

Nice tweak, thank you! The reason why it didn't do this from the beginning is because of my use of the file. When I was using it for my project, it was more convenient to just output it to a .txt file.


* - JoshuTee - Apr 22, 2017

It looks pretty nice, but why bother with batch when you can directly make a VBS without any temporary files?


* - Beigevenus - Apr 22, 2017

(Apr 22, 2017 07:27 AM)JoshuTee Wrote:  It looks pretty nice, but why bother with batch when you can directly make a VBS without any temporary files?

I'm not sure I understand what you mean? Is it because it outputs to a .txt file? Because that was actually for personal convenience for the project I was using it for. And thank you XD