问题描述
我正在制作一个可以打字的机器人,但当它按下输入键时,程序会关闭,但未完成
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,(s,))
s.run()
我在论坛上找到了这段代码来创建一个循环,该循环在重复之前等待 x 时间,但是当涉及到 pyauogui.press('enter') 这行时它会关闭,这是为什么?
解决方法
我运行了你的代码并遇到了同样的问题,然后我查看了它,在第 5 行你有一个类型“pyaugui.press('enter')”,你现在可能已经猜到它拼写为 pyautogui,如上面和导入语句中的行。
*
我已经测试过了,现在可以运行了。我建议您使用带有内置错误突出显示功能的 IDE 或文本编辑器。
示例:
Visual Studio 代码 (Microsoft) - https://code.visualstudio.com/
Visual Studio (Microsoft) - https://visualstudio.microsoft.com/
PyCharm (Jetbrains) https://www.jetbrains.com/pycharm/
所有这些都是免费的(PyCharm 有付费版本)
,你只是犯了一个小错误......正确地查看你的源代码......
pyauogui.press('enter')
虽然没有名为 pyauogui
的函数。它应该是 pyautogui
。这是一个错字错误...
import sched,time,pyautogui
s = sched.scheduler(time.time,time.sleep)
def do_something(sc):
pyautogui.write('hello')
pyautogui.press('enter')
s.enter(30,1,do_something,(sc,))
s.enter(5,(s,))
s.run()