/*
*
*
* How_app.js - Key Pressing script, based on one to automate the EUA
*
* Automating typing into the App using Windows shell scripts and javascript.* 
*
* Doug Rice, BT (C) 15/03/2016, 16/03/2016, 12/01/2019, 23/03/2021
*
* https://msdn.microsoft.com/en-us/library/8c6yea83(v=vs.84).aspx
* https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/windows-scripting/8c6yea83(v=vs.84)
*
*   wscript How_app.js  
/*
**********************************************************************************
* SEC 2.0 MAIN
**********************************************************************************
*/
	WScript.Echo( "Starting Script..press OK then select input area, typing starts after 3 seconds" );
	var WshShell = WScript.CreateObject("WScript.Shell");
	//http://www.nilpo.com/2007/08/windows-xp/scripting-the-clipboard-contents-in-wsh/
	var count = 0


	WScript.Sleep(3000); // wait for selected number to go blue

		
/* Agent typing */
	var strApp=  " This is BeeTea Engineer, DHR, making a test call.\n Please hang up the B-leg \n"+
	" I am testing the new Relay UK app \n"+
	" Hello Doug here \n "+
	" Can you see my typing? \n "+
	" The Quick brown fox jumps over the lazy dog \n "+
	" I am testing the new Relay UK app \n "+
	"\n"
	//" 1 2 3 4 5 6 7 8 9 ! £ $ % ^ & * ( ) _- + = { } [ ] ~ # : ; @ ' < > , . / ?"


/* Agent typing */
	var strTRA = " Welcome to Chit Chat UK  \n " +

	" Please type you name? \n  " +
	" You are talking to Jack \n " +
	" How May I help you today \n " +
	" Okay I will type back? \n  " +
	" The Quick brown fox jumps over the lazy dog \n " +
	" Hello Caller the other party has cleared. \n " +
	" \n "
		
		
		
	finished = ( 1 == 0 )
	while( ! finished ){
	  //WScript.Sleep(500); // wait for selected number to go blue
	  WScript.Sleep( 0+Math.random()*50 ); // wait for selected number to go blue  
	  nextKey = strTRA.substr( count, 1 )		
      WshShell.SendKeys ( nextKey );
	  if ( nextKey == " " ){ WScript.Sleep( 50+Math.random()*300 ) }
	  if ( nextKey == "\n" ){
		WshShell.SendKeys ( "~" );	
		WScript.Sleep( 500+Math.random()*3000 ) 
	  }
	  finished = ( 1 == 1 )
	  count = count + 1
	  finished = ( count > strTRA.length  )
	}