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

Time:12-24

I'm having problems because Controller names match for both mouse and keyboard, so try doing this.

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)

But it is giving me this argument error, that if I used them importing directly to each one it would not happen

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

CodePudding user response:

According to the documentation of pynput the controllers should be instantiated

mouseController = pynput.mouse.Controller()

keyboardController = pynput.keyboard.Controller()
  • Related