Possible Duplicate:
How can I make a while True break if certain key is pressed? [Python]
我有这个代码:
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()
它是这样工作的:
当我按F2时,脚本将填写一些表单并等待我的enter登录,然后,当我按enter时,脚本跳转到屏幕的某个部分并检查该部分是否是链接(enterCategory()部分),如果是链接,则脚本会成功执行我想要的操作,但如果登录出错,位置[4]和[5]将永远不会出现一个链接,脚本将在无限循环。。。在
我怎么解决这个问题?当我按F2键时,它存在于while并再次尝试登录时,我该怎么做呢?在
对不起,如果我不能理解=/
您可以使用F2的处理来将一个全局标志(例如,一个名为
proceed
)设置为False
,而现在有了while win32gui...
,则改为have不雅观,但也不是用光标形状分析来找出鼠标是否在链接上;-)。在
相关问题 更多 >
编程相关推荐