Python and SendKeys
import SendKeys, threading, pyHook, pythoncom
class Auto(threading.Thread):
def run(self):
SendKeys.SendKeys("{ENTER}",pause=0.1);
print('Sent');
exit();
def OnKeyboardEvent(event):
if event.Ascii == 22:
Auto().start();
return True
hm = pyHook.HookManager()
hm.KeyDown = OnKeyboardEvent
hm.HookKeyboard()
pythoncom.PumpMessages()
For some reason this program fails after running it exactly two times, I have no idea what the cause for this is. When you comment out the SendKeys part the program runs fine, so it has to be a problem with send keys.
[edit] Also, to clarify, running SendKeys.SendKeys(...) in a for i in range(0,100) works, so I assume it's something to do with the thread. I've never programmed threads before. Also this is just a mockup example to replicate the problem.
I'm running on windows 7, python2.6
[edit]Also, the program doesn't 'fail' it simply freezes (the function isn't run at all, it just sits there)