Automatically Rerun Button

Is there a way to automatically rerun a dynamo script, used as a pushbutton, until I hit the escape key?

I know that on the pyRevit ribbon, there’s the match function where you can do a similar concept but I’m not as fluent in python yet.

Hi @bschneiderhan, maybe you already figured out, but this is my take.

What you need is a never ending loop with while True and a condition to break out of it.

To read the key presses, you should be able to do it with the msvcrt module.

Since the msvcrt.getch function is blocking (it waits until you press a key), you first need to check if a key has been pressed with the msvcrt.kbhit function.

So your code could be like this:

import msvcrt

def esc_pressed():
    return msvcrt.kbhit() and ord(msvcrt.getch()) == 27

while True:
    if esc_pressed():
        break
    # place your repeating code here...

Note: this is what I found on stack overflow after 5 minutes of google search.
I also didn’t test it, it might be that the msvcrt module won’t work in revit/pyrevit… give it a try and let us know if that worked!