While loop until right mouse click in python

I want to run a method until right mouse button is clicked. how can i do this?

-Eivind

What exactly are you trying to do?


# Local smoothing

def SelectBrushSmooth():
    rs.Command("_-SelBrushPoints", False)
    grips = rs.SelectedObjectGrips(objectId)
    importCommand = "-_Smooth " + " -_Enter"
    rs.Command(importCommand, False)
    rs.UnselectObjectGrips(objectId)

#While loop inside main method
while True:
        SelectBrushSmooth()
        if scriptcontext.escape_test(False):
            print "ESC pressed "
            break      #get out of the loop

I want a way to cancel this scripted tool for local smoothing. if i hold down esc or press it mulitple times, so it first exits SelectedObjectGrips and then the while loop.

i just want a better way to exit the loop or if anyone has other ideas i have not tested. i am normaly up for anything! since it is the user experience that is important.