Home > Software engineering >  Pressing a key multiple time in batch file
Pressing a key multiple time in batch file

Time:09-06

I have a script which is used to insert data in a web form.There is some data in the form field initially, before inserting the new data i want to clear the field so that i can type new data.To achieving this I am using the multiple backspace.Is there any method by which i can press any key multiple time instead of writing the same code in multiple lines. Or any syntax which can simulate Ctl A key which is used to select all.My code goes as follows

@if (@CodeSection == @Batch) @then
@echo off
setlocal enabledelayedexpansion
set SendKeys=CScript //nologo //E:JScript "%~F0"
START msedge "https://fams.nabard.org:48443/PanaceaFAMS/login.faces"

timeout /t 6
!SendKeys! "{BACKSPACE}"
!SendKeys! "{BACKSPACE}"
!SendKeys! "{BACKSPACE}"
!SendKeys! "{BACKSPACE}"
!SendKeys! "{BACKSPACE}"
!SendKeys! "{BACKSPACE}"
!SendKeys! "{BACKSPACE}"
!SendKeys! "{BACKSPACE}"
!SendKeys! "{BACKSPACE}"
!SendKeys! "43569"
!SendKeys! "{TAB}"  
@end
// JScript section

var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));

CodePudding user response:

Perhaps this idea would make more sense to you. It should send each key as you've shown, but does so by executing CScript only once, which is much more efficient:

<!-- :
@Echo Off
SetLocal EnableExtensions DisableDelayedExpansion

Set "LURL=https://fams.nabard.org:48443/PanaceaFAMS/login.faces"
Set "Keys={BS} {BS} {BS} {BS} {BS} {BS} {BS} {BS} {BS} 43569 {TAB}"

Set "Edge=%ProgramFiles(x86)%\Microsoft\Edge\Application\msedge.exe"
Set "Wait=%SystemRoot%\System32\timeout.exe"
Set "CScr=%SystemRoot%\System32\cscript.exe"

Start "" "           
  • Related