Types more than once - need to wait for image to vanish

Asked by Alex Craske

So I'm new to this and need a basic code, it scans a region waits for an image to appear, when it does it types F once and then waits for the image to appear again a second or two later.

Here is my code:
while True:
    if exists("V.png") : type("F")

The issue is that it types F over and over as long as the image is there, now the image will usually stay up for a second then go down then come back a second or two after that, so I would like it to type F, wait for a second, then look for the image again.

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

--- possibility 1: image driven waits

while True:
    if exists("V.png") :
        type("F")
        waitVanish("V.png")

if image comes up, it waits until image vanished again.
Tip: exists, wait and waitVanish have an optional time parameter (see docs), that could extend the max waiting time beyond the standard 3 seconds

--- possibility 2: static waits

while True:
    if exists("V.png") :
        type("F")
        wait(3)

This would wait fix for 3 seconds (other than waitVanish, which reacts on the image and the max given waiting time)

Revision history for this message
j (j-the-k) said :
#2

To optimize the speed of your script, you could also use:

while True:
    match = exists("V.png")
    if match:
        type("F")
        match.nearby(10).waitVanish("V.png")

As always this is just an addition to RaiMan's already great answer ;-)

Revision history for this message
RaiMan (raimund-hocke) said :
#3

@ j-the-k
Thanks for your comment.
Good idea, to add a margin around the matched image for the waitVanish().

I already thought about wether the image might be different after the type(), so one has to take another screenshot and a search region relative to the match.

Can you help with this problem?

Provide an answer of your own, or ask Alex Craske for more information if necessary.

To post a message you must log in.