Help with SIMPLE moving pixels to the right of an image

Asked by rbranch7

I dont understand why it's been so time consuming figuring out how to shift the mouse a few pixels to the right of a found image.
Lets say I can successfuly locate an image. After locating it, I want to click 150 pixels to the right of it.

This line of code terminates my program without warning:
 find(sortedMatches[-1]).targetOffset(150,0)

is it really that difficult to click xpixels to the right of a found image?

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
Best RaiMan (raimund-hocke) said :
#1

find(sortedMatches[-1]).targetOffset(150,0)

since this is the only information you gave us, we have to guess:
sortedMatches probably contains a list of matches evaluated by findAll() before.

The docs would have told you, that find needs an image or image pattern as parameter.
Staying with the guess: you seem to use the last match in the match list, which is not allowed as parameter with find

That SikuliX-IDE silently dies in this case I take as a bug (internally the wrong parameter is detected and reported as error, but you cannot see that message (only when running from commandline), because SikuliX-IDE is terminated)
You could have seen that, when running your script from a commandline.

conclusion:
sortedMatches[-1].targetOffset(150,0)

would give you the wanted location and

click(sortedMatches[-1].targetOffset(150,0))
would do the wanted job

Revision history for this message
rbranch7 (rickydbranchjr) said :
#2

I beleive that I am getting an error because sortedlist[] has a list of Match objects. What would I do to offset the click of a Match object 150pixels?
sortedMatches is defined by this
sortedMatches = sorted(findAll(Pattern("1457227433201.png").exact()), key=by_nearest)

where the key is the distance measure from the mouse

your suggestion:
click(sortedMatches[-1].targetOffset(150,0))

[error] TypeError ( 'org.sikuli.script.Location' object is not callable )

Revision history for this message
rbranch7 (rickydbranchjr) said :
#3

Thanks RaiMan, that solved my question.

Revision history for this message
rbranch7 (rickydbranchjr) said :
#4

I figured out the issue. I looked into the match documentation which extends Region. The sortedMatches element was a match, so I used the left(dx) method on it.

t = sortedMatches[-1].left(-550)
click(t)

Sorry about the confusion