Random click region (no images)

Asked by xyz_User on 2019-12-31

Trying to basically click randomly within the "r" region - there are no images to look for
Tried this from another topic but it doesn't seem to click within the specified region:

import random
r = Region(246,444,153,113)
locx = int(r.w * random.random())
locy = int(r.h * random.random())
click(Location(locx, locy))

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
Manfred Hampl
Solved:
2020-01-02
Last query:
2020-01-02
Last reply:
2019-12-31
Best Manfred Hampl (m-hampl) said : #1

Location is a position on the screen, not necessarily in your region, and its position is relative to the screen corner.
see https://sikulix-2014.readthedocs.io/en/latest/location.html

Try

locx = r.x + int(r.w * random.random())
locy = r.y + int(r.h * random.random())
click(Location(locx, locy))

xyz_User (userseven) said : #2

Thanks Manfred Hampl, that solved my question.