Execute script with middle mouse

Is there a way to execute a python script with the middle mouse button, but also still having the ability to rotate the view with the middle mouse? Basically have one button able to execute two functions at the same time.

Checkout this page to see how to construct an addon (including keyboard/mouse shortcuts). If you check the api here, you’ll see that MIDDLEMOUSE is an option for use as a shortcut. Under the ‘value’ option on the same page, you can choose if you want the function to run with a mouse PRESS, RELEASE, CLICK, or DOUBLECLICK value. Have you already tried doing this?