skai2/EDAutopilot

keyboard module needs root permissions

Closed this issue · 3 comments

keyboard module needs root permissions

Traceback (most recent call last):
  File "autopilot.py", line 31, in <module>
    tray()
  File "/home/speed/Desktop/EDAutopilot/dev_tray.py", line 73, in tray
    keyboard.add_hotkey('home', start_action)
  File "/home/speed/.local/lib/python3.6/site-packages/keyboard/__init__.py", line 639, in add_hotkey
    _listener.start_if_necessary()
  File "/home/speed/.local/lib/python3.6/site-packages/keyboard/_generic.py", line 35, in start_if_necessary
    self.init()
  File "/home/speed/.local/lib/python3.6/site-packages/keyboard/__init__.py", line 196, in init
    _os_keyboard.init()
  File "/home/speed/.local/lib/python3.6/site-packages/keyboard/_nixkeyboard.py", line 113, in init
    build_device()
  File "/home/speed/.local/lib/python3.6/site-packages/keyboard/_nixkeyboard.py", line 109, in build_device
    ensure_root()
  File "/home/speed/.local/lib/python3.6/site-packages/keyboard/_nixcommon.py", line 174, 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.

when I run the script as root I get

Traceback (most recent call last):
  File "autopilot.py", line 1, in <module>
    from dev_tray import tray
  File "/home/speed/Desktop/EDAutopilot/dev_tray.py", line 3, in <module>
    from dev_autopilot import autopilot, resource_path, get_bindings, clear_input, set_scanner, RELEASE
  File "/home/speed/Desktop/EDAutopilot/dev_autopilot.py", line 43, in <module>
    from pyautogui import size# see reference 6
  File "/home/speed/.local/lib/python3.6/site-packages/pyautogui/__init__.py", line 94, in <module>
    import mouseinfo
  File "/home/speed/.local/lib/python3.6/site-packages/mouseinfo/__init__.py", line 149, in <module>
    _display = Display(os.environ['DISPLAY'])
  File "/home/speed/.local/lib/python3.6/site-packages/Xlib/display.py", line 80, in __init__
    self.display = _BaseDisplay(display)
  File "/home/speed/.local/lib/python3.6/site-packages/Xlib/display.py", line 62, in __init__
    display.Display.__init__(*(self, ) + args, **keys)
  File "/home/speed/.local/lib/python3.6/site-packages/Xlib/protocol/display.py", line 129, in __init__
    raise error.DisplayConnectionError(self.display_name, r.reason)
Xlib.error.DisplayConnectionError: Can't connect to display ":1": b'No protocol specified\n'

when I add root to the access control list, mentioned here it still doesn't work.

Traceback (most recent call last):
  File "autopilot.py", line 1, in <module>
    from dev_tray import tray
  File "/home/speed/Desktop/EDAutopilot/dev_tray.py", line 3, in <module>
    from dev_autopilot import autopilot, resource_path, get_bindings, clear_input, set_scanner, RELEASE
  File "/home/speed/Desktop/EDAutopilot/dev_autopilot.py", line 154, in <module>
    logging.info('get_latest_log='+str(get_latest_log(PATH_LOG_FILES)))
  File "/home/speed/Desktop/EDAutopilot/dev_autopilot.py", line 143, in get_latest_log
    list_of_logs = [join(path_logs, f) for f in listdir(path_logs) if isfile(join(path_logs, f)) and f.startswith('Journal.')]
FileNotFoundError: [Errno 2] No such file or directory: '/home/root/.steam/steamapps/compatdata/359320/pfx/drive_c/users/steamuser/Saved Games/Frontier Developments/Elite Dangerous'

@SpeedrunnerG55 were you able to solve this in your fork without breaking windows compatibility? if so i recently forked this project to fix some other issues, mostly 4K compatibility, but i am on windows and would like to make my fork more compatible and would be interested in discussing your changes with you.

@TomW1605 I ended up just replacing the keyboard module entirely with input because keyboard needed root privileges, it caused me to run into other issues. however, that does not have to do with this issue. as far as breaking windows compatibility, I'm not sure because of the way I'm handling the keyboard is entirely different from the original author. using the pynpus module instead of keyboard and ctypes. ill just push what I have now then, its still buggy and a bit bodged