dimanche 22 mai 2022

Import "pynput.keyboard" could not be resolved from source Pylance (reportMissingImports)

I am trying to write some code that essentially types a random 5 character word. I can't get pynput.keyboard to work as I keep getting the same error message (Import "pynput.keyboard" could not be resolved from source) my code:

from pynput.keyboard import Key,Controller
keyboard = Controller()
from random import randrange
import time


alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
word = []

for i in range(5):
    x = randrange(1,26)
    #rint(x)
    l1 = alphabet[x-1]
    #print(l1)
    word.append(l1)

y = ''.join(word)
time.wait(5)
keyboard.press(y)
keyboard.release(y)

I already did

pip3 install pynput

My problem seems to be similar to this one that I found. https://www.reddit.com/r/learnpython/comments/jqepj8/i_think_python_hates_me_import_pynputmouse_could/




Aucun commentaire:

Enregistrer un commentaire