can't find a way to click at a random pixel

Asked by solaire25 on 2018-09-26

Hi, i have been using Sikuli quite often but most of the times i simply copied the code since iam really at programming... But i wanted to get started myself and improving my programming skills. I mainly using Sikuli for different games i used to play and having some troubles with my latest project: I use the click(pattern...) and want to click at a random pixel within a given range around the center of the picture...

I've alrdy tried different approaches e.g.:

# use this where ever needed
x = random.randint(0, 250)
y = random.randint(0, 250)

if exists(Pattern("1537959580441.png"):

---but its still clicking the same spot over and over

i tried using the offset on a set location and it worked perfectly fine:

click(Location(1163, 558).offset(random.randint(0,250), random.randint(0,60)))

So my question: is there an easy way to set a random clicking offset using a pattern?

thank you

Question information

English Edit question
Sikuli Edit question
No assignee Edit question
Solved by:
Last query:
Last reply:
RaiMan (raimund-hocke) said : #1


must be:

solaire25 (solaire25) said : #2

Ok i think i need to refine my question, i do have a while loop and it clicks at the same spot while the script/loop is running. Is there a way to make sikuli click different every time while the loop is running?

thank you

Best RaiMan (raimund-hocke) said : #3

click(Pattern("1537960842723.png").similar(0.90).targetOffset(random.randint(0, 250),random.randint(0, 250)))

should click somewhere else every time it is processed (e.g. in a loop)

RaiMan (raimund-hocke) said : #4

if you want to click around the center use instead:
random.randint(-100, 100)

solaire25 (solaire25) said : #5

Thanks RaiMan, that solved my question.