怎样才能用钥匙退出一段时间? [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 时,脚本跳转到一部分屏幕并检查该部分是否是链接(enterCategory() 部分),如果是链接,则脚本成功执行我想要的操作,但如果登录出现问题,则位置 [4] 和 [5]永远不会成为链接,并且脚本将无限循环......
我该如何解决这个问题?我怎样才能做一些事情,以便当我按 F2 时,它会存在一段时间并再次尝试登录?
抱歉,如果我听不懂=/
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 =/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 F2 的处理将全局标志(例如,名为
proceed
的标志)设置为False
,现在您有while win32gui...< /code>,有,而
不是 不优雅,但是光标形状分析也不是确定鼠标是否位于链接上;-)。
You could use the handling of F2 to set a global flag (e.g., one named
proceed
) toFalse
, and where you now havewhile win32gui...
, have, insteadNot elegant, but then neither is the cursor-shape analysis to find out if the mouse is on a link;-).