help plos
help plos

Reputation: 1

keyboard erroring on one line but not the other

why does it error on the second keyboard? pycharms does not show the error but it still breaks, vsc and sublime both identify this error

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()

Upvotes: 0

Views: 22

Answers (1)

FilipA
FilipA

Reputation: 612

Your error message is caused by:

time.sleep((random.uniform(0.1, 0.3)

You are missing "))" at the end to close the brackets. Change it to:

time.sleep((random.uniform(0.1, 0.3)))

ADDITIONALLY: Also I believe it's more common to write

keyboard.press('w')

instead of

keyboard.press("w")

Upvotes: 1

Related Questions