Python Forum
mouse library demands root access - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: mouse library demands root access (/thread-34203.html)



mouse library demands root access - ineuw - Jul-07-2021

Using either pip3 install mouse and sudo pip3 install mouse generate the following error when importing the library into a script (Autokey).

# [win + z]

import mouse, time

i = 1
while i < 2:
    mouse.move(265, 116, absolute=True, duration=0.2)
    time.sleep(0.2)
    keyboard.wait_for_keypress("<escape>", timeOut=1.0)
    mouse.click("right") ###
    time.sleep(0.2)
    keyboard.send_keys("<alt>+<shift>+s")
    i = 1
What am I doing wrong?

Error:
Traceback (most recent call last): File "/home/ineuw/.local/lib/python3.8/site-packages/autokey/service.py", line 530, in _execute exec(compiled_code, scope) File "/home/ineuw/.config/autokey/data/macros/win-z.py", line 10, in <module> mouse.click("right") File "/home/ineuw/.local/lib/python3.8/site-packages/mouse/__init__.py", line 93, in click _os_mouse.press(button) File "/home/ineuw/.local/lib/python3.8/site-packages/mouse/_nixmouse.py", line 105, in press build_device() File "/home/ineuw/.local/lib/python3.8/site-packages/mouse/_nixmouse.py", line 72, in build_device ensure_root() File "/home/ineuw/.local/lib/python3.8/site-packages/mouse/_nixcommon.py", line 165, in ensure_root raise ImportError('You must be root to use this library on linux.') ImportError: You must be root to use this library on linux.



RE: mouse library demands root access - deanhystad - Jul-07-2021

You need to run your program as root. It is listed as a limitation of the package.
Quote:Known limitations:
To avoid depending on X the Linux parts reads raw device files (/dev/input/input*) but this requries root.
Have you lookd at PyAutoGUI?


RE: mouse library demands root access - ineuw - Jul-08-2021

Apologies for the delay in replying. Many thanks for your advice. PyAutoGUI is installed, but haven't used it yet. That's next.