Question #659989 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/659989
Status: Open => Answered
RaiMan proposed the following answer:
ok, I have to admit, that for Java the docs are not really helpful - I
will optimize that ;-)
Here is a working example for an onChange observation:
a helper for the formatted printout:
private static void p(String msg, Object... args) {
System.out.println(String.format(msg, args));
}
the example:
Region reg = new Region(0,0,80,80); // define the observed region
reg.highlight(2);
reg.onChange(new ObserverCallBack(){ // define the handler
@Override
public void changed(ObserveEvent evt) {
if (evt.getCount() > 3) {
p("in handler: %d - stopping", evt.getCount());
evt.stopObserver();
} else {
p("in handler: %d", evt.getCount());
}
}
});
reg.observeInBackground(); // start observation in background forever
int n = 0;
while (reg.isObserving()) { // do something while observe is running
p("%d - observing", n);
reg.wait(1.0);
n++;
}
which prints something like this:
[log] highlight R[0,0 80x80]@S(0) for 2.0 secs
0 - observing
in handler: 1
1 - observing
2 - observing
3 - observing
4 - observing
in handler: 2
5 - observing
in handler: 3
6 - observing
in handler: 4 - stopping
--- some comments
- if you want to track some motion or some continuous change, then you have to
either loop around an observe(time) or use a construct like the above example
with an observe in background.
- in your main workflow, you have to track wether anything happens at all and
if it does, when nothing happens anymore (which is not implemented in the
example), but which is needed in your case.
come back if you need more help
--
You received this question notification because your team Sikuli Drivers
is an answer contact for Sikuli.
_______________________________________________
Mailing list: https://launchpad.net/~sikuli-driver
Post to : [email protected]
Unsubscribe : https://launchpad.net/~sikuli-driver
More help : https://help.launchpad.net/ListHelp