I'm a beginner to python and don't understand what's wrong with my code. I'm using pynput

from pynput.keyboard import Key, Controller
keyboard = Controller()
import time
import random
while True:
    timebetweentypes = random.randint(300, 86400)
    time.sleep(timebetweentypes)
    typed = random.choice('1''2''3''4''5''6''7''8''9''q''w''e''r''t''y''u''i''o''p''a''s''d''f''g''h''j''k''l''z''x''c''v''b''n''m''Q''W''E''R''T''Y''U''I''O''P''A''S''D''F''G''H''J''K''L''Z''X''C''V''B''N''M''!''"''£''$''%''^''&''*''('')'',''.''<''>''/''?''@'':'';''~''#'"'"
    keyboard.type(typed)

** The word 'keyboard' on line 9 gets highlighted in red and python tells me that it's a syntax error.

Upvotes: 0

Views: 112

Answers (4)

sgcoder1337
sgcoder1337

Reputation: 63

  1. On line 8, put commas between the objects in the list.
  2. Close the bracket at the end of the list.

Upvotes: 1

python-coder12345
python-coder12345

Reputation: 188

You missed a ) at the line behind all the characters. They think you are continuing the line so the final line will not work.

Upvotes: 1

Eeshaan
Eeshaan

Reputation: 1635

Close the bracket on the 8th line. Also you've to separate the characters with a comma. A much simpler way to do it is

typed = random.choice('1 2 3 4 ... # "'.split())

(... represents all the characters you want. I'm just too lazy to type out.)

Upvotes: 1

user12886328
user12886328

Reputation:

In the typed variable, there must be a comma after each object like: 'A','B','C','D'

Upvotes: 1

Related Questions