怎样才能用钥匙退出一段时间? [Python]

发布于 2024-09-16 18:47:28 字数 1110 浏览 1 评论 0原文

可能的重复:
我该如何制作如果按下某个键则真正中断? [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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

戒ㄋ 2024-09-23 18:47:28

您可以使用 F2 的处理将全局标志(例如,名为 proceed 的标志)设置为 False,现在您有 while win32gui...< /code>,有,而

global proceed
proceed = True
while proceed and win32gui...

不是 不优雅,但是光标形状分析也不是确定鼠标是否位于链接上;-)。

You could use the handling of F2 to set a global flag (e.g., one named proceed) to False, and where you now have while win32gui..., have, instead

global proceed
proceed = True
while proceed and win32gui...

Not elegant, but then neither is the cursor-shape analysis to find out if the mouse is on a link;-).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文