Stopping iterations in python
<p>I'm relatively new to coding, and I made this program to repeat mouse strokes when I am on a certain webpage so that the process can be automated. </p>

<pre><code>import pyautogui, time

inp = raw_input("Number input?")
iterations = raw_input("Iterations?")

def move(x, y):
    pyautogui.moveTo(x, y)

for i in range(int(iterations)):
    move(540,515)
    pyautogui.click()
    move(690,760)
    pyautogui.click()
    pyautogui.typewrite(inp)
    move(1200,790)
    pyautogui.click()
    move(1200,340)
    pyautogui.click()
</code></pre>

<p>If I inputted too many iterations or I need to control my mouse again before the iterations are complete, is there a way to stop the loop/iterations? I tried to use CTRL+BREAK, but it didn't stop the loop. I also tried to add KeyboardInterrupt by using CTRL+C, but I couldn't figure out how to do it for my script.</p>

<p>For ctrl + C to work, the active window must be the one with the terminal running python.</p>

<p>I guess that it may be tricky when you have your program clicking everywhere...</p>

<p>Now to make an answer worth your while, I introduce you to web browsing with python : <a href="http://selenium-python.readthedocs.io/getting-started.html#simple-usage" rel="nofollow">http://selenium-python.readthedocs.io/getting-started.html#simple-usage</a></p>

<p>This way your program can run in background and you can kill it whenever you want.</p>

python loops break