random click

Asked by Peter Darbyshire

at the moment i have

Wait for image to be found
Click
Wait for image to be found
Click

how to make the click to be random. i.e. click in different places on the image found?

Thanks

Question information

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

--- click somewhere
m = wait(image)
click(m.getCenter().right(x).below(y))

-- m is the found match.
-- click(m) would click the center, getCenter() returns this pixel position
-- right(x), below(y) add x to the current x position, y to the current y position and return a new pixel position
-- if you set x and y to the respective values negative or positive, you might click wherever you want

--- if you want to randomize x and y:
use Python module random:
import random # at beginning of script

# use this where ever needed
x = random.randint(0,m.w)-int(m.w/2)
y = random.randint(0,m.y)-int(m.y/2)

now you have random x and y values, every time it is used

Can you help with this problem?

Provide an answer of your own, or ask Peter Darbyshire for more information if necessary.

To post a message you must log in.