How to use Target offset functionality in java

Asked by Saorabh Singh

How to use Target offset functionality in java??

i want to click a bottom of a picture..
How can i Achive this??

picture Size is not constant...So we have to get bottom value or say point of click dynamically..

Please Help me out..

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Saorabh Singh (kunnu30) said :
#1

This is one way ...& its working.

r=s.exists(Image,1);
Region select=r.below();
select.h=5;
s.click(select, 1);

But i want to know can we use Target offset functionality in java??

Revision history for this message
Best RaiMan (raimund-hocke) said :
#2

of course you can do.

targetOffset is a Pattern attribute. You have to calculate/evaluate/guess the target offset some how.

usage:

Pattern pImage = new Pattern(Image).targetOffset(x,y)
r=s.exists(pImage,1);
s.click(r, 1)

would click at the target offset position (which is r.getCenter().right(x).below(y)).

Revision history for this message
Saorabh Singh (kunnu30) said :
#3

Thanks RaiMan, that solved my question.

Revision history for this message
Lasya Kiran (lasyakiran) said :
#4

What is the import that I need to make to use Pattern attribute?

Revision history for this message
Seth Carter (sundaymtn) said :
#5

@Lasya the import is "import org.sikuli.script.Pattern;"
my syntax ended up being:

    Pattern pImage = new Pattern(fullPath("close.png")).targetOffset(30,0);
    Match r = s.exists(pImage, 1);
    s.click(r, 0);

Revision history for this message
Lasya Kiran (lasyakiran) said :
#6

Thanks Seth for the quick reply, but is this for Sikuli script? Not, Sikuli Java API?

I am actually looking for the same in Sikuli Java API 1.0.2

Thank you!