I am fairly new to Python
, I recently made this program to automatically click a text box in a program and type text (hello). But everytime I run the program, it says:
Instance of 'Controller' has no 'type' member.
I am using pynput
and Python 3.8.1 32bit
. I installed pynput
manually through the console with
pip install pynput
Here is my code:
import time
from pynput.keyboard import Key, Controller
from pynput.mouse import Button, Controller
def controlMouse(x, y):
mouse = Controller()
mouse.position = (x, y)
def controlKeyboard(txt):
keyboard = Controller()
keyboard.type(txt)
def clickMouse():
mouse = Controller()
mouse.click(Button.left, 1)
def pressKeyboard(key):
keyboard.press(Key.key)
keyboard.release(Key.key)
mouse = Controller()
controlMouse(268, 1030)
time.sleep(1)
clickMouse()
time.sleep(1)
controlMouse(400, 955)
time.sleep(1)
clickMouse()
controlKeyboard('Hello')
pressKeyboard(enter)
You have this:
from pynput.keyboard import Key, Controller
from pynput.mouse import Button, Controller
After that, Controller
refers to pynput.mouse.Controller
(because it was the last time Controller
was defined). If you want to be able to refer to both Controller
types, you should do something like this:
from pynput.keyboard import Key, Controller as KeyboardController
from pynput.mouse import Button, Controller as MouseController
You can then use KeyboardController
and MouseController
to refer to the right kind of Controller
.
Alternatively, you can:
import pynput.keyboard
import pynput.mouse
You can then just refer to pynput.keyboard.Controller
and pynput.mouse.Controller
.