PyAutoGui循环中断

时间:2018-12-03 21:47:42

标签: python-3.x while-loop pyautogui

因此,我一直在互联网上搜索,以弄清楚我在这里做错了什么。基本上,我想创建一个脚本,该脚本将提示用户输入数字,然后多次执行crtl v paste操作。我尝试了以下变化的变化,但它不起作用。这些命令在循环外部运行良好,但是当我尝试循环运行时,程序崩溃了。我可能错过了一些明显的东西,但是我一直在努力寻找过去2小时内没有任何运气的东西。任何帮助表示赞赏。

import time
import pyautogui

x = input()

time.sleep(5) #delays the next process by 5 seconds

def work():
    global x
    pyautogui.hotkey('ctrl','v')
    time.sleep(.25)
    pyautogui.press('enter')
    time.sleep(.25)
    x = x - 1

try:    
    while x > 0:
        work()
    else:
        pass

except KeyboardInterrupt:
    pass

1 个答案:

答案 0 :(得分:0)

好的,我知道了。 x> 0是问题所在。如代码所示,x是一个字符串,您不能将字符串与整数进行比较。

所以我所做的就是在用户输入后添加此

public NavigationViewComponent(
    IContextManager contextManager,
    IAuthorizationService authorizationService)
{
    _contextManager = contextManager;
    _authorizationService = authorizationService;
}

public async Task<IViewComponentResult> InvokeAsync()
{
    var showAdmin = _contextManager.Principal != null &&
        (await _authorizationService.AuthorizeAsync(_contextManager.Principal, "Admin")).Succeeded;

    var vm = new NavigationViewModel
    {
        ShowAdmin = showAdmin
    };

    return View(vm);
}

现在,它可以完美运行。如果我已经从命令窗口运行了程序,我将在数小时前发现此问题。下次我会知道的。