Package org.sikuli.api

Examples of org.sikuli.api.ScreenRegion


  public static void main(String[] args) {
    simulator.start();

    Rectangle b = simulator.getBounds();
    ScreenRegion s = new DesktopScreenRegion(b.x,b.y,b.width,b.height);
   
    ScreenRegion icon1 = s.find(new ImageTarget(Images.PersonIcon));;
    ScreenRegion icon2 = s.find(new ImageTarget(Images.ThumbIcon));;
    ScreenRegion icon3 = s.find(new ImageTarget(Images.TwitterBirdIcon));;

    canvas.addBox(icon1);
    canvas.addBox(icon2);
    canvas.addBox(icon3);
    canvas.display(1);
View Full Code Here


 
    simulator.setSize(800,800);
    simulator.start();
   
    Rectangle b = simulator.getBounds();
    ScreenRegion s = new DesktopScreenRegion(b.x,b.y,b.width,b.height)

    Target target;
    List<ScreenRegion> rs;

    // find all unchecked checkboxes ordered from bottom to top 
   
    target = new ImageTarget(Images.UncheckedCheckbox);
    target.setLimit(15);
    target.setOrdering(Target.Ordering.BOTTOM_UP);
   
    rs = s.findAll(target);
   
    canvas.addLabel(Relative.to(s).topLeft().getScreenLocation(), "Unchecked checkboxes found in bottom-up ordering");
    for (int i=0; i < rs.size(); ++i){
      ScreenRegion r = rs.get(i);
      canvas.addBox(r);
      canvas.addLabel(Relative.to(r).topLeft().left(20).getScreenLocation(), ""+(i+1));
    }
    canvas.display(5);
       
    // find all styled rectangles (e.g., buttons) ordered from left to right
 
    target = new StyledRectangleTarget(Images.ButtonOptions);
    target.setOrdering(Target.Ordering.LEFT_RIGHT);
   
    rs = s.findAll(target);
   
    canvas.clear().addLabel(Relative.to(s).topLeft().getScreenLocation(), "Rectangles found in left-right ordering");
    for (int i=0; i < rs.size(); ++i){
      ScreenRegion r = rs.get(i);
      canvas.addBox(r);
      canvas.addLabel(Relative.to(r).topLeft().left(20).getScreenLocation(), ""+(i+1));
    }
    canvas.display(5);
View Full Code Here

 
 
  public static void main(String[] args) {
    simulator.start();   
    Rectangle b = simulator.getBounds();
    ScreenRegion s = new DesktopScreenRegion(b.x+10,b.y+30,b.width-20,b.height-40)
   
    canvas.addBox(s);
    canvas.addLabel(Relative.to(s).topLeft().getScreenLocation(), "Observed region");
    canvas.display(2);
   
    Target target = new ForegroundTarget();
    ScreenRegion r = s.find(target);   
   
    canvas.clear();
    canvas.addBox(r);
    canvas.addLabel(Relative.to(s).topLeft().getScreenLocation(), "find");
    canvas.addLabel(Relative.to(r).topLeft().getScreenLocation(), "foreground object");
View Full Code Here

   
    simulator.start();

    Rectangle b = simulator.getBounds();
   
    ScreenRegion s = new DesktopScreenRegion(b.x, b.y, b.width, b.height);
    canvas.addBox(s).display(2);               

    StateChangeListener l = new StateChangeListener(){              

      @Override
      public void stateChanged(StateChangeEvent event) {
        System.out.println(event.getScreenRegion() + "'s state is changed " +
            "from {" + event.getOldState() + "} " +
            " to {" + event.getNewState() + "}");     
       
       
        String txt = event.getOldState() + "->" + event.getNewState();
        ScreenLocation labelLocation = Relative.to(event.getScreenRegion()).topLeft().above(20).getScreenLocation();
        canvas.clear().addLabel(labelLocation,txt).display(1);
      }         
    };

    ScreenRegion personIcon = s.wait(new ImageTarget(Images.PersonIcon),1000);   
    canvas.clear().addBox(personIcon).display(1);
   
    ScreenRegion statusIcon = Relative.to(personIcon).right(30).getScreenRegion();
    canvas.clear().addBox(personIcon).display(1);   

    statusIcon.addState(new ColorImageTarget(Images.GreenBullet), "GREEN");
    statusIcon.addState(new ColorImageTarget(Images.RedBullet), "RED");
    statusIcon.addState(new ColorImageTarget(Images.SilverBullet), "SILVER");
    statusIcon.addStateChangeEventListener(l);

  }
View Full Code Here

 
  public static void main(String[] args) {
   
    simulator.start();            
    Rectangle b = simulator.getBounds();
    ScreenRegion s = new DesktopScreenRegion(b.x, b.y, b.width, b.height);

    List<ScreenRegion> rs;
    Target target = new ImageTarget(Images.HollowRedStar);
    target.setOrdering(Ordering.LEFT_RIGHT);
    rs = s.findAll(target);         

    ScreenRegion left = rs.get(0);
    ScreenRegion right = rs.get(1);

    left = Relative.to(left).taller(30).wider(30).getScreenRegion();
    right = Relative.to(right).taller(30).wider(30).getScreenRegion();

   
    canvas.addBox(s);
   
    canvas.addBox(left);
    canvas.addLabel(left, "left");   

    canvas.addBox(right);
    canvas.addLabel(right, "right");
    canvas.display(3);
   
    simulator.resume();   

    StateChangeListener l = new StateChangeListener(){              

      @Override
      public void stateChanged(StateChangeEvent event) {
        System.out.println(event.getScreenRegion() + "'s state is changed " +
            "from {" + event.getOldState() + "} " +
            " to {" + event.getNewState() + "}")
       
        canvas.clear();
        canvas.addLabel(event.getScreenRegion(), event.getOldState() + "->" + event.getNewState());
        canvas.display(1);
      }         
    };


    left.addState(new ColorImageTarget(Images.HollowGreenStar), "GREEN");
    left.addState(new ColorImageTarget(Images.HollowRedStar), "RED");
    left.addState(new ColorImageTarget(Images.HollowBlueStar), "BLUE");
    left.addStateChangeEventListener(l);

    right.addState(new ColorImageTarget(Images.HollowGreenStar), "GREEN");
    right.addState(new ColorImageTarget(Images.HollowRedStar), "RED");
    right.addState(new ColorImageTarget(Images.HollowBlueStar), "BLUE");
    right.addStateChangeEventListener(l);

  }
View Full Code Here

    simulator.resume();
   
    canvas.clear();
   
    // Finding color bullets
    ScreenRegion greenBullet = s.wait(new ColorImageTarget(Images.GreenBullet),10000);
    ScreenRegion redBullet = s.find(new ColorImageTarget(Images.RedBullet));
    ScreenRegion silverBullet = s.find(new ColorImageTarget(Images.SilverBullet));
   
    canvas.addBox(greenBullet);   
    canvas.addLabel(Relative.to(greenBullet).topLeft().above(20).getScreenLocation(), "green");
   
    canvas.addBox(redBullet);
View Full Code Here

    // iterate through each screen, the mouse cursor will traverse along the edges
    // of a rectangle centered on each screen clockwise, and then clicks on the dog image
    int numOfScreens = DesktopScreen.getNumberScreens();
    for (int screenId = 0; screenId < numOfScreens; screenId++){
     
      ScreenRegion screenRegion = new DesktopScreenRegion(screenId);
      ScreenRegion innerRegion = Relative.to(screenRegion).shorter(100).narrower(100).getScreenRegion();

      // create a canvas to draw visualization on the screen
      Canvas c = new ScreenRegionCanvas(screenRegion);
      c.addBox(innerRegion);
      c.addLabel(innerRegion.getCenter(), "Screen " + screenId).withFontSize(30);
      c.addImage(Relative.to(innerRegion).center().above(200).getScreenLocation(), ImageIO.read(Images.Dog));
      c.show();
     
      // hover the mouse cursor to each corner of the inner circle
      mouse.hover(Relative.to(innerRegion).topLeft().getScreenLocation());
      mouse.hover(Relative.to(innerRegion).topRight().getScreenLocation());
      mouse.hover(Relative.to(innerRegion).bottomRight().getScreenLocation());
      mouse.hover(Relative.to(innerRegion).bottomLeft().getScreenLocation());
     
      // find the dog and click on it
      ScreenRegion dog = innerRegion.find(new ImageTarget(Images.Dog));
      mouse.click(dog.getCenter());
     
      c.hide();
    }
   
 
View Full Code Here


  public static void main(String[] args) {
    simulator.start();

    ScreenRegion s = new DesktopScreenRegion()

    ScreenRegion dog = s.find(new ImageTarget(Images.Dog));
    ScreenRegion cat = s.find(new ImageTarget(Images.Cat));
   
    mouse.click(dog.getCenter());
    mouse.click(cat.getCenter());

    mouse.rightClick(dog.getCenter());
    mouse.rightClick(cat.getCenter());

    mouse.hover(dog.getCenter());
    mouse.hover(cat.getCenter());
    mouse.hover(dog.getCenter());
   
    mouse.hover(cat.getCenter());   
    mouse.press();   
    mouse.release();
   
    mouse.hover(dog.getCenter());   
    mouse.rightPress();   
View Full Code Here

 
  public static void main(String[] args) {   
   
    simulator.start();

    ScreenRegion s = new DesktopScreenRegion();

    URL imageURL = Images.OSXDockIcon;               
    Target imageTarget = new ImageTarget(imageURL);

    ScreenRegion r = s.find(imageTarget);
    mouse.click(r.getCenter());   

    imageURL = Images.ThumbIcon;               
    imageTarget = new ImageTarget(imageURL);

    r = s.wait(imageTarget, 5000);
    mouse.click(r.getCenter());

    imageURL = Images.CheckedCheckbox;               
    imageTarget = new ImageTarget(imageURL);         

    r = s.wait(imageTarget, 5000);
    mouse.click(r.getCenter());
   
    imageURL = Images.OSXDockIcon;
    imageTarget = new ImageTarget(imageURL);
    r = s.wait(imageTarget, 5000);
   
View Full Code Here

  };

  public static void main(String[] args) {
    simulator.start();
    Rectangle b = simulator.getBounds();
    ScreenRegion s = new DesktopScreenRegion(b.x,b.y,b.width,b.height);
       
    // create an image target based on an image of a checked checkbox
    ImageTarget checked = new ImageTarget(Images.CheckedCheckbox);
    // create an image target based on an image of an unchecked checkbox
    ImageTarget unchecked = new ImageTarget(Images.UncheckedCheckbox);
   
    // create a multi-state target to look for checkboxes
    MultiStateTarget target = new MultiStateTarget();
    // add the "checked" state specified by the image target of a checked checkbox
    target.addState(checked, "checked");
    // add the "unchecked" state specified by the image target of an unchecked checkbox
    target.addState(unchecked, "unchecked");
       
    // find all the checkboxes, both checked and unchecked
    List<ScreenRegion> checkboxes = s.findAll(target);
    for (ScreenRegion c : checkboxes){
      // get the state of each checkbox
      String state = (String) c.getState();
      // display the state next to each checkbox to visualize
      ScreenLocation labelLocation = Relative.to(c).topLeft().left(70).below(10).getScreenLocation();
View Full Code Here

TOP

Related Classes of org.sikuli.api.ScreenRegion

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.