Possible Duplicate:
How can I make a while True break if certain key is pressed? [Python]
I have this code:
def enterCategory():
time.sleep(0.2)
if entercount == 1:
mouseMove(*position[5])
while win32gui.GetCursorInfo()[1] != 65567:
mouseMove(*position[5])
mouseMove(*position[4])
mouseLeftClick()
def onKeyboardEvent(event):
if event.KeyID == 13: #ENTER
print '\n'
mouseLeftClick()
enterCountInc()
enterCategory()
print '\n'
if event.KeyID == 113: #F2
doLogin()
enterCountReset()
return True
hook.KeyDown = onKeyboardEvent
hook.HookKeyboard()
pythoncom.PumpMessages()
and it work like this:
When I press F2, the script will fill some forms and wait for my enter to login, then, when I press enter, the script jump to a part of the screen and check if that part is a link (enterCategory() part), and if it's a link, the script do successfully what I want, but if something goes wrong with the login, the position[4] and [5] will never be a link, and the script will be at infinity loop...
How can I solve that? How can I do something so when I press F2, it exist the while and try the login again?
Sorry if I'm not understandable =/