How to loop entire Script

Asked by Jeramie Ingram

Thanks for any advice on this.

I am trying to make a simple auto click script that I would like to repeat until I stop with Hotkeys.
This is my first try at any kind of scripting. I have no prior knowledge on scripts or python. I have though looked at all of the FAQs on here looking for looping solutions. I tried a few but cant seem to get any to work. I also saw something that I should create a function and then loop the function. See my code below:

I would like this to run infinite until I stop

 running = True

def runHotkey(event):
    global running
    running = False

Env.addHotkey(Key.ESC, KeyModifier.SHIFT+KeyModifier.CTRL, runHotkey)

click(Location(41,1300))
click(Location(38,1179))
wait(1)
click(Location(367,965))
click(Location(420,991))
click(Location(450,965))
click(Location(475,1055))
click(Location(555,1055))
click(Location(677,968))
click(Location(885,1300))
click(Location(890,1180))
wait(1)
click(Location(1250,967))
click(Location(1265,991))
click(Location(1295,965))
click(Location(1328,1055))
click(Location(1410,1055))
click(Location(1528,968))
wait(300)

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Manfred Hampl
Solved:
Last query:
Last reply:
Revision history for this message
Best Manfred Hampl (m-hampl) said (last edit ):
#1

What you need can be found by a web search for "python while".

running = True

def runHotkey(event):
    global running
    running = False

Env.addHotkey(Key.ESC, KeyModifier.SHIFT+KeyModifier.CTRL, runHotkey)

while running:
    click(Location(41,1300))
    click(Location(38,1179))
    wait(1)
    click(Location(367,965))
    click(Location(420,991))
    ...
    (all commands to be repeated need to be indented by the same amount of whitespace)

Remark: You have to make sure, that the hotkey that you select does not conflict with hotkeys in other programs, especially in the operating system. As far as I know, on a Windows system ctrl-shift-esc starts the task manager and this has precedence, such that this key combination does not work in Sikulix on Windows.

Revision history for this message
Jeramie Ingram (user868name) said :
#2

Thanks this worked to loop the script.

And thanks for fast reply, I have been away from email for a while.