← Back to team overview

sikuli-driver team mailing list archive

[Bug 1206879] Re: [1.0] Java: Screen.selectRegion()/userCapture() hang, when used in JFrame/JButton handler --- must be outside the handler

 

Something like this works:

*** implement your own "wait for something happens" loop.

package org.sikuli.testselectregion;

import java.awt.Container;
import java.awt.event.ActionEvent;
import java.beans.PropertyChangeListener;
import javax.swing.Action;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import org.sikuli.script.*;
import org.sikuli.basics.*;

/**
 * Hello world!
 *
 */
public class App {
  
  public static JFrame w;
  public static boolean clicked;
  public static Screen s = new Screen();

  public static void main(String[] args) {
    w = new JFrame("testSelectRegion");
    Container pane = w.getContentPane();
    pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
    JButton b = new JButton("ClickMe");
    b.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        w.setVisible(false);
        clicked = true;
      }
    });
    pane.add(b);
    w.pack();
    clicked = false;
    w.setVisible(true);
    while (! clicked) {
      s.wait(1.0);
    }
    Region r = s.selectRegion();
    SikuliScript.popup(r.toStringShort());
    System.exit(0);
  }
}

-- 
You received this bug notification because you are a member of Sikuli
Drivers, which is subscribed to Sikuli.
https://bugs.launchpad.net/bugs/1206879

Title:
  [1.0] Java: Screen.selectRegion()/userCapture() hang, when used in
  JFrame/JButton handler --- must be outside the handler

Status in Sikuli:
  In Progress

Bug description:
  What I am trying to accomplish is to select an area on the screen with
  the mouse (outside of the may frame) and get the resulting region
  coordinates using Sikuli.

  The code that should do this looks is below:

  Screen screen = Screen.getPrimaryScreen();
  Region region = screen.selectRegion("Select the area.");
  What happens is that the cursor turns into a selector cross (the ones you usually see when you expect this function), but I can't select the area and actually the only way I can get back from the application is by killing it. Not too many examples I have found so I am asking for help here.

  How can I make this work?

  Also one other question:

  I have downloaded the following script version:

  Sikuli-IDE-1.0.0-Win64.zip

  This means if I want to create a crossplatform solution I have to
  include like 6 jars? I have found a more universal Java API it seems
  (that is what it is called actually):

  https://code.google.com/p/sikuli-api/

  With all required supported OS but I can't find a single example on
  what I am trying to do that is similar to the little code snippet I
  pasted here. The sikuli script I am using now and this Sikuli API
  (apparently not the same) seems to be just different enough to amke
  this difficult.

  Any suggestions? Thanks a lot in advance.

To manage notifications about this bug go to:
https://bugs.launchpad.net/sikuli/+bug/1206879/+subscriptions


References