← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #163613]: After a script runs 50 times I want to add a different keystroke to the script, how do I code that?

 

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

    Status: Open => Answered

RaiMan proposed the following answer:
Generally, this is done with if/elif/else:

example:

if n <= 60:
          type("T")
elif n > 60 and n < 70:
          type("1")
elif n > 69 and n < 80:
          type("X")
else
          type("Z")

If the script gets to this, it will check the content of and will
-- type("T"), if it is less than 61 (<=60)
-- type("1"), if it is in the range 61 to 69 inclusive
-- type("X"), if it is in the range 70 to 69 inclusive
-- type("Z") in all other cases 

You may have as many elif's (or none) between the if and the else (which
might not be there) .

if it is only one line after if/elif/else, you might do it this way:

if n == 60: type("1")
else: type("Z")

so my guess in your case:

for n in range(100):
          wait(6)
          if n == 60:
                  type("1")
          else:
                  type("T")
          find(<image>)
          click(<image>)
          type(Key.ESC)
          hover(<second image>)
          wait(20)
          rightClick(<third image>)

One more thing:
To indent, it seems you are taking 8 blanks. The recommendation general and and especially in the Sikuli IDE, is to use a tab to indent one level and shift-tab to dedent one level. The IDE manages internally, to make each tab/shift-tab to be 4 blanks.

You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.