moses-palmer / pynput

Sends virtual input commands
GNU Lesser General Public License v3.0
1.79k stars 248 forks source link

Mac OS pynput mouse click issue #321

Closed Catalyst-42 closed 3 years ago

Catalyst-42 commented 3 years ago

-- console output -- File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pynput/mouse/_base.py", line 90, in press self._press(button) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pynput/mouse/_darwin.py", line 111, in press (press, , _), mouse_button = button.value AttributeError: 'str' object has no attribute 'value'

-- python code -- from pynput.keyboard import Key, Controller from pynput.mouse import Button, Controller

mouse = Controller() mouse.click(Button.left, 1)

keyboard = Controller() keyboard.press('1') keyboard.release('1')

-- versions -- Python 3.9.0 Pynput 1.7.1 Mac OS Catalina 10.15.7

moses-palmer commented 3 years ago

Your import of pynput.mouse.Controller shadows your import of pynput.keyboard.Controller, so you are attempting to use a mouse controller as keyboard controller on the line keyboard.press('1'); please use a different name for each controller.

In my tests I generally import the top level modules keyboard and mouse, and access the controllers with the qualified names: keyboard.Controller and mouse.Controller.