Shows how to use the SimulateTouch method

Code from the DroidScript-Beta forum posted by Dave Smart.

Here is an example which automatically keeps pressing a button forever (Note you can simulate “Up”, “Down” and “Move” events)

Simulattouch.js
//Called when application is started.
function OnStart()
{
	//Create a layout with objects vertically centered.
	lay = app.CreateLayout( "linear", "VCenter,FillXY" );	
 
	//Create image 1/5 of screen width and correct aspect ratio.
	img = app.CreateImage( "/Sys/Img/Hello.png", 0.2, -1 );
	lay.AddChild( img );
 
	//Create a button 1/3 of screen width and 1/10 screen height.
	btn = app.CreateButton( "Press Me", 0.3, 0.1 );
	btn.SetMargins( 0, 0.05, 0, 0 );
	lay.AddChild( btn );
 
	//Set function to call when button pressed.
	btn.SetOnTouch( btn_OnTouch );
 
	//Add layout to app.	
	app.AddLayout( lay );
}
 
//Called when user touches our button.
function btn_OnTouch()
{
    app.Vibrate( "0,100,30,100,50,300" );
    setTimeout( SimTouch, 1000 );
}
 
function SimTouch()
{
    //Method1
    app.SimulateTouch( btn );
 
    //Method2
    /*
    app.SimulateTouch( btn, 0.5, 0.5, "Down" );
    app.Wait( 0.1 );
    app.SimulateTouch( btn,  0.5,  0.5, "Up" );
    */
}