pythonautokey

How to run autokey python script as root


I have a python script that requires using keyboard however it always fail to run with:

ImportError: You must be root use this library on linux.

I do want to run it as root, but how do I go about doing this in autokey (as I need the hotkey functionality)?

Script that triggers that error just for reference:

# Enter script code
import time, random, keyboard
while True:
    mouse.click_relative_self(0,0,1)
    time.sleep(random.randint(1,3))
    if keyboard.is_pressed('q'):
        break

I've already installed via pip all libraries.


Solution

  • I kinda was looking for a GUI way to do it, but the easiest way is to just launch Autokey in terminal like:

    sudo autokey
    

    And just copy/paste the script in that sudoed Autokey GUI.

    Of course considering all libraries are already installed via pip.