← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #692019]: [request] Randomized mouse route from A to B?

 

Question #692019 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/692019

    Status: Open => Answered

RaiMan proposed the following answer:
import random
m = find("1595940323624.png")

click(m.offset(random.randint(0,100), random.randint(0,100)))
wait(random.randint(1,10))
click(m.offset(random.randint(0,100), random.randint(0,100)))
wait(random.randint(1,10))
click(m.offset(random.randint(0,100), random.randint(0,100)))
wait(random.randint(1,10))
click(m.offset(random.randint(0,100), random.randint(0,100)))


--- click(m.offset(random.randint(0,100), random.randint(0,100))
depending on the width and height of m, the random click point might be outside of m.
... and it is always right of the center of m

You should pack the special features in functions to save repeated code.

With your example:
import random

def clickR(someImageOrPattern, around = 5):
    match = find(someImageOrPattern) # find image
    target = match.getCenter().grow(around) # target area around pixels around center of match
    mouseMoveRandom(target, 50, 50) # move mouse on a randomized track to a randomized point inside target
    click(Mouse.at()) # now finally click there
    return match

img = "1595940323624.png"
clickR(img, around = 100)
for n in range():
    wait(random.randint(1,10))
    clickR(img, around = 100)

Since I am short on time with other priorities, you now have to find
your way.

-- 
You received this question notification because your team Sikuli Drivers
is an answer contact for Sikuli.