← Back to team overview

sikuli-driver team mailing list archive

[Question #453545]: Let click in a region randomly

 

New question #453545 on Sikuli:
https://answers.launchpad.net/sikuli/+question/453545

Hello ,I have some question of coding siklui in Java.
Question1 :
 I want let sikuli to find a image location,and click it randomly.
My code is work for me ,but my code seems can be more easier .

Here is my code01:
----------------------------------------------------------
class Randomcb  {
	Screen s = new Screen();
	Region reg = new Screen();
	Random ran = new Random();
	private int Rx,Ry,Rh,Rw,fx,fy;
	public void RndClik(String Path)
	{
	Rx = reg.exists(Path).getX();
    Ry = reg.exists(Path).getY();
    Rh = reg.exists(Path).getH();
    Rw = reg.exists(Path).getW();
    
  	fx=Rx+ran.nextInt(Rw);
  	fy=Ry+ran.nextInt(Rh);
  	Location Lr =new Location(fx,fy);
  	  
    try{ s.click(Lr);}
    catch(FindFailed e){e.printStackTrace();}
    }
----------------------------------------------------------
And I can call by folowing:

Randomcb randomcb= new Randomcb();
randomcb.RndClik("image path");


Question2 :
I want just move mouse to a location by coordinate

Here is my code02
----------------------------------------------------------
public void MoveTo(int bx,int by)
	{
		reg.x=bx;
reg.y=by;
		Location  Lr2= new Location(reg.x, reg.y);
		 try{reg.mouseMove(Lr2);}
		 catch(FindFailed e){e.printStackTrace();}		
	}
----------------------------------------------------------

----------------------------------------------------------


-- 
You received this question notification because your team Sikuli Drivers
is an answer contact for Sikuli.