Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 一行出现键盘错误,但另一行没有_Python - Fatal编程技术网

Python 一行出现键盘错误,但另一行没有

Python 一行出现键盘错误,但另一行没有,python,Python,为什么它在第二个键盘上出错?pycharms没有显示错误,但仍然会中断,vsc和sublime都会识别此错误 import time import pyautogui from pynput.keyboard import Key, Controller import random keyboard = Controller() start = input("do you want to start: ") def main(): print("sta

为什么它在第二个键盘上出错?pycharms没有显示错误,但仍然会中断,vsc和sublime都会识别此错误

import time
import pyautogui
from pynput.keyboard import Key, Controller
import random

keyboard = Controller()

start = input("do you want to start: ")

def main():
    print("starting")
    while True:
        time.sleep(5)
        keyboard.press("w")
        print("holding w")
        time.sleep((random.uniform(0.1, 0.3)
        keyboard.release("w") #error line
        print("released w")


if start == "yes":
    main()

您的错误消息是由以下原因引起的:

time.sleep((random.uniform(0.1, 0.3)
您在结束时缺少“)”以关闭括号。 将其更改为:

time.sleep((random.uniform(0.1, 0.3)))
此外: 我也相信写作更常见

keyboard.press('w')
而不是

keyboard.press("w")

欢迎使用StackOverflow,请将您的错误代码和文本添加到您的PostThank filipA中,我一定会在明天使用计算机时尝试,我也会使用“”而不是“”,因为我通常使用vb.net,我相信到目前为止还没有引起任何问题!