How do determine the x & y coordinates

Asked by Al Alder

Since some of the Sikuli commands require the x or y coordinates on the screen, how do I determine what those are?

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

Not really clear what you mean :-(

--- 1st guess:
All Region and Match objects know their position on the screen.
Their x and y (the regions upper left corner) can be either printed in the message area
print find("some-img.png")
prints something like that:
Match[10,176 340x45] score=1,00, target=center

or can be extracted
m = find("some-img.png")
print "x-value =", m.x
print "x-value =", m.y
prints something like that:
x-value = 10
y-value = 176

since x and y are numbers, you can calculate with them:
click(Location(m.x+100, m.y+100)
logs something like that:
[log] CLICK on (110,276)

--- 2nd guess
you see something on the screen and want to no a (x,y) pixel position to e.g. calculate an offset or width/height.

Most screen capture tools show pixel information while capturing or preparing it.

If you do not have one of these, you can use Sikuli script also:

-- 1st possibility:
run this command in a new tab in the IDE:
print selectRegion()
and select something on the screen that makes sense for you
It prints something like that:
Region[119,176 147x69]@Screen(0) E:Y, T:3,0

-- 2nd possibility (more accurate)
put this command in a new tab in the IDE:
print Env.getMouseLocation()

the usage is a bit more complicated, since you cannot use the mouse ;-)
-- make visible on the screen, what you are interested on
-- move the mouse to the point of interest
-- go back to Sikuli IDE using the keyboard (ctrl-tab on windows, cmd-tab on Mac)
-- press ctrl-R/cmd-R to run the script
It prints something like that:
(117,128)
which is your (x,y)

Hope it helps.

Revision history for this message
Al Alder (avalder) said :
#2

Thank you RaiMan, you fully answered my question. Sikuli rocks!