Francesco Piccolomini
Francesco Piccolomini

Reputation: 25

sikulix ask user to click on location and save it

Is there a way to ask the user to click on a Location and save the coordinates to use that Location later?

None of the tools isted in the page https://sikulix-2014.readthedocs.io/en/latest/interaction.html are suitable for the job, i think.

Upvotes: 0

Views: 95

Answers (2)

Raimund Hocke
Raimund Hocke

Reputation: 126

This is RaiMan from SikuliX

Eugene's answer is absolutely correct: Currently SikuliX does not have any features to get feedback, when a user clicks somewhere on the screen.

But for your request there is a rather simple solution:

simg = userCapture("select location (center of capture)") # capture with prompt
loc = None # None means user did not capture (ESC)
if simg != None:
    loc = simg.getRegion().getCenter() # the location to use as center of capture
print loc

This will tell the user to capture a region, that has its center at the wanted location. The internal capture result (ScreenImage) knows its coordinates on the screen.

Hope it helps ;-)

Upvotes: 2

Eugene S
Eugene S

Reputation: 6910

There are two parts to your question.

  1. Asking user to click.
  2. Recording mouse click location.

The first item seems to be irrelevant for Sikuli. You will have to use some other tools to do that. Regarding the second question, the answer is:

  1. It is impossible to be notified by Sikuli about a user click event.
  2. You can get a current mouse location but that of course does not guarantee an actual user click.

To get current mouse location (not click):

getmouseLoc = Env.getMouseLocation()
x = getmouseLoc.getX()
y = getmouseLoc.getY()

Upvotes: 1

Related Questions