Global hotkey to stop windows script
<p>I'm working on a script that grabs control of my mouse and runs within a simple infinite while loop.</p>

<pre><code>def main():
    while True:
        do_mouse_stuff()
</code></pre>

<p>Because of the mouse control, it's a pain to click on the python window and hit ctrl-c, so I've been looking for a way to implement a global hotkey in windows. I'm also a relative Python noob so I've probably missed an obvious answer. Stuff I've found:</p>

<p>pyhk - the closest I've gotten, but this module does nasty things to my computer for some reason (probably something I'm doing wrong), it introduces major mouse lag, complete input lockout, all kinds of stuff I'm not smart enough to deal with.</p>

<p>pyHook - Followed the <a href="http://sourceforge.net/apps/mediawiki/pyhook/index.php?title=PyHook_Tutorial" rel="nofollow">tutorial</a>, works fine but the infinite running message pump and my while loop appear to run exclusively and I haven't figured out how to make it work.</p>

<p><a href="http://timgolden.me.uk/python/win32_how_do_i/catch_system_wide_hotkeys.html" rel="nofollow">Another Method</a> - I found this method as well, but I have the same problem as pyHook, the try loop and my while loop cannot coexist.</p>

<p>I've tried to figure out how to integrate my loop into these examples rather than maintaining a separate loop but I've not been able to make that work, again likely due to my noobishness. Would someone be able to straighten me out on how to make this work?</p>
