python - python在执行时关闭 pyautogui.press('enter')
问题描述
我正在制作一个可以打字的机器人,但是当它按下输入时,程序在未完成时关闭
import sched, time, pyautogui
s = sched.scheduler(time.time, time.sleep)
def do_something(sc):
pyautogui.write('hello')
pyauogui.press('enter')
s.enter(30, 1, do_something, (sc,))
s.enter(5, 1, do_something, (s,))
s.run()
我在论坛上找到了这段代码来创建一个循环,该循环在重复之前等待 x 次,但是当涉及到 pyauogui.press('enter') 行时它会关闭,这是为什么?
解决方案
I ran your code and got the same issue, then I looked at it and in line 5 you have a type "pyaugui.press('enter')" as you may guess by now it is spelt pyautogui as seen in the line above and in your import statement.
# Fixed Code
import sched, time, pyautogui
s = sched.scheduler(time.time, time.sleep)
def do_something(sc):
pyautogui.write('hello')
# Your type was here
pyautogui.press('enter')
s.enter(30, 1, do_something, (sc,))
s.enter(5, 1, do_something, (s,))
s.run()
I've tested and it now runs. I can recommend getting a IDE or text editor with built in error highlighting.
Examples:
Visual studio code (Microsoft) - https://code.visualstudio.com/
Visual studio (Microsoft) - https://visualstudio.microsoft.com/
PyCharm (Jetbrains) https://www.jetbrains.com/pycharm/
All of these are free (PyCharm has a paid version)
推荐阅读
- python - pandas.read_json() 没有按预期工作
- php - 如何使用 SSH 连接到 Laravel 目录?
- java - 多个文件的 Firestore 查询过滤器
- excel - Excel VBA 宏抓取
- django - 检查权限类中的条件
- python - 如何一次在多个维度上执行 reduce_op?
- php - 教义和码头工人的问题
- android - Google Drive Api 已弃用(Google play games -> Saved Games)
- alexa - Alexa skills - fulfilling another slot in slot filling process
- slf4j - Dropwizard metrics slf4j reporter configuration