'Controller' 的实例没有 'type' 成员 pynput 模块
Instance of 'Controller' has no 'type' member pynput module
我是 Python
的新手,我最近制作了这个程序来自动单击程序中的文本框并键入文本 (hello)。但是每次我 运行 这个程序,它都会说:
Instance of 'Controller' has no 'type' member.
我正在使用 pynput
和 Python 3.8.1 32bit
。我使用
通过控制台手动安装了 pynput
pip install pynput
这是我的代码:
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)
你有这个:
from pynput.keyboard import Key, Controller
from pynput.mouse import Button, Controller
之后,Controller
指的是pynput.mouse.Controller
(因为是最后一次定义Controller
)。如果你想引用两种 Controller
类型,你应该这样做:
from pynput.keyboard import Key, Controller as KeyboardController
from pynput.mouse import Button, Controller as MouseController
然后您可以使用 KeyboardController
和 MouseController
来指代正确的 Controller
。
或者,您可以:
import pynput.keyboard
import pynput.mouse
然后您可以只参考 pynput.keyboard.Controller
和 pynput.mouse.Controller
。
我是 Python
的新手,我最近制作了这个程序来自动单击程序中的文本框并键入文本 (hello)。但是每次我 运行 这个程序,它都会说:
Instance of 'Controller' has no 'type' member.
我正在使用 pynput
和 Python 3.8.1 32bit
。我使用
pynput
pip install pynput
这是我的代码:
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)
你有这个:
from pynput.keyboard import Key, Controller
from pynput.mouse import Button, Controller
之后,Controller
指的是pynput.mouse.Controller
(因为是最后一次定义Controller
)。如果你想引用两种 Controller
类型,你应该这样做:
from pynput.keyboard import Key, Controller as KeyboardController
from pynput.mouse import Button, Controller as MouseController
然后您可以使用 KeyboardController
和 MouseController
来指代正确的 Controller
。
或者,您可以:
import pynput.keyboard
import pynput.mouse
然后您可以只参考 pynput.keyboard.Controller
和 pynput.mouse.Controller
。