尝试使用pynput同时使用键盘和鼠标控制方法时出错

Error trying to use keyboard and mouse control methods at the same time with pynput

我遇到了问题,因为鼠标和键盘的控制器名称都匹配,所以请尝试这样做。

import pynput

mouseController = pynput.mouse.Controller
mouseButton = pynput.mouse.Button

keyboardController = pynput.keyboard.Controller
keyboardKey = pynput.keyboard.Key

keyboardController.press (keyboardKey.space)
keyboardController.release (keyboardKey.space)

mouseController.click (mouseButton.left, 2)

但是它给了我这个参数错误,如果我使用它们直接导入到每个参数就不会发生

keyboardController.press(keyboardKey.space)
TypeError: press() missing 1 required positional argument: 'key'

根据 pynput 的文档,应该实例化控制器

mouseController = pynput.mouse.Controller()

keyboardController = pynput.keyboard.Controller()