Easy way to take screenshot and region at the same time

Asked by Full Name on 2018-07-19

Hello, thank you a lot for making and maintaining Sikuli, I am programming illiterate but I managed to make a few simple scripts where it clicks on some stuff which is immensely helpful to automate tedious tasks.

I have two questions, First: Is there an easy way to take a screenshot and define a region at the same time in the exact same space? I want to check for an image at an exact region, but when I use the screenshot and region commands in the header and select them myself with the mouse It is hard to pixel perfect select the exact same place on my screen for screenshots and regions

Secondly: is there a way to click at the place an image has been found with the "exists" command without using regions command? I want to click on a fading image that can appear on random places of the screen. I tried using
if exists(image):
    click(image)
But then sometimes because the image is fading between where it checks for the image to exists and actually clicking it the image faded just enough that the script doesn't detect it anymore and therefore the script breaks (because it tries to click on something that doesn't exist anymore at this point).

Thanks in advance

Question information

Language:
English Edit question
Status:
Answered
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Last query:
2018-07-19
Last reply:
2018-07-19
RaiMan (raimund-hocke) said : #1

--- at first:

I understand, that you have captured an image (capturedImage) and now want to have the exact region, this image occupies on the screen.

imageRegion = find(image)

now imageRegion is that region and you can say:

match = imageRegion.find(anotherImage)

which searches for anotherImage inside the region imageRegion.

--- at second:
if exists(image):
    click()

the click will immediately click what was found with exists() before (no repeated search)

generally: someRegion.click() will click what was found with the latest find-op in that region someRegion.
when using just click(), the region is the whole screen (as with just exists())

BE AWARE: this all is true and working for SikuliX 1.1.2+ (using 1.1.3 nightly is recommended)

Can you help with this problem?

Provide an answer of your own, or ask Full Name for more information if necessary.

To post a message you must log in.