Is there any way to click relative coordinates?

Asked by caijimin

Like dragDrop(t, [t.x - 200, t.y]), we can use relative coordinates to explicitly drag to the left,

What I want to do is:

    t = find(img)
    click([t.x - 200, t.y])

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
caijimin
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

this worked for me:

t = find(img)
t1= capture(t.getx, t.gety, t.getw, t.geth)
click(t1)

when building the parms for captur(), you can play around ;-)

t is of class match: http://sikuli.org/doc/edu/mit/csail/uid/Match.html

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

Sorry, I have to correct:

t1= capture(t.getX(), t.getY(), t.getW(), t.getH())

Revision history for this message
caijimin (caijimin) said :
#3

Thank you. worked for me!

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

this should even be faster:

t1= Match(t.getX(), t.getY(), t.getW(), t.getH(), 1) # just creates a new match object with simularity = 1 (exact)

Revision history for this message
j4ke (jake-mailinator) said :
#5

Hello,

I was wondering if there is any possible way to use..

t = regionimg.inside().find(img)
t1= capture(t.getx, t.gety, t.getw, t.geth)
click(t1)

..without getting the getX attribute error, t = find(img) works but it makes the script very slow compared to finding in a specific region of course.

Thanks,

Jake

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

No problem- just try:

t = Subregion(x, y, w, h).inside().find(img)
t1= Match(t.getX(), t.getY(), t.getW(), t.getH(), 1) # just creates a new match object with simularity = 1 (exact)
click(t1)

Subregion(x, y, w, h): this can be created visually in the IDE by using the right icon (find within subregion) of the 3 icons left top. Or you can calculate (x, y, w, h) by yourself (same way as with the Match above). then you have to write it down as written. Its also possible to calculate the four parameters for the match.

example: say you know what your looking for is in the upper left quarter of the screen (e.g. 1280 x 720):
t = Subregion(0, 0, 640, 360).inside().find(img)
...
...

Revision history for this message
j4ke (jake-mailinator) said :
#7

I tried, but it is still giving AttributeError: getX even if I make the similarity to default and to "1" in the t image and the t1 Match. I need to use a similar though in the t image because it is not exact at most times and how could I exactly calculate the four parameters for the Match t1 when between these regions Subregion(521, 283, 220, 201) ? I tried doing something like this:

   t = Subregion(521, 283, 220, 201).inside().find(img)
   t1 = None
   if t:
      thex = t.getX()
      t1 = Match(thex, t.getY() + 35, t.getW(), t.getH(), 1)
      click(t1)
      click(t1)
      click(t1)
      sleep(5)
      type(" ")

but still gave me the AttributeError: getX , I'm pretty sure thats not correct way but is there a way to assign variables the t images x, y, w, h?

Thanks,

Jake

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

Its really weird - I will post a bug - if interested look their (A match x=find(img) works, but x=Subregion().inside().findimg) leads to the error, but the match object seems to be the same)

But I may have found a circumvention - try this
t = Subregion(521, 283, 220, 201).inside().find(img)
t = find.region
print t # in the IDE message area, you will find the details of the match

comment:
find() stores the best found match in find.region. If you use this match instead (which should by content be the same) getX, ... work as they should.

Another tip:
If you use a pattern object instead of an image you can influence the needed/expected simularity and the number of matches to find. So if you are rather sure (as it seems to be in your situation), I guess you will get a better performance when using find this way:
t = Subregion(521, 283, 220, 201).inside().find(Pattern(img).simular(1).firstN(1))

simular(1) says "match has to be exact" and firstN(1) stops the search after the first match.

Interested in the class definitions? http://sikuli.org/doc/allclasses-noframe.html

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

Sorry, type error simular - should read
... find(Pattern(img).similar(1).firstN(1))