简体   繁体   中英

Python Key-logger (.error.DisplayNameError: Bad display name “”)

I was following up on a tutorial to build a python keylogger and ended up with this problem. I have gone over my codes about 10 times and compared it with other sources but yet still getting the same error. I have seen similar complaints while looking for a solution, and I hypothesize that it might be my computer( Mac OSX 10.12 sierra, MacBook Pro (13-inch, Mid 2010)). I am not a computer expert so I am not too sure. If it is my system architecture, how do I by-pass it? if not, what am I missing in the code or where is my error?

 import pyxhook

log_file =  "/Users/VemPC/Desktop/log_file.log"


def onPress(event):
    fob = open(log_file, 'a')
    fob.write(event.key)
    fob.write('\n')
    if event.key.ascii == 96 :
        fob.close()
        new_hook.cancel()


new_hook = pyxhook.HookManager()
new_hook.KeyDown = onPress
new_hook.HookKeyboard()
new_hook.start()





 Error:
Traceback (most recent call last):
  File "key_logger.py", line 15, in <module>
    new_hook = pyxhook.HookManager()
  File "/Users/VemPC/Desktop/Challenges/venv/lib/python3.7/site-packages/pyxhook/pyxhook.py", line 67, in __init__
    self.local_dpy = display.Display()
  File "/Users/VemPC/Desktop/Challenges/venv/lib/python3.7/site-packages/Xlib/display.py", line 89, in __init__
    self.display = _BaseDisplay(display)
  File "/Users/VemPC/Desktop/Challenges/venv/lib/python3.7/site-packages/Xlib/display.py", line 71, in __init__
    protocol_display.Display.__init__(self, *args, **keys)
  File "/Users/VemPC/Desktop/Challenges/venv/lib/python3.7/site-packages/Xlib/protocol/display.py", line 85, in __init__
    name, protocol, host, displayno, screenno = connect.get_display(display)
  File "/Users/VemPC/Desktop/Challenges/venv/lib/python3.7/site-packages/Xlib/support/connect.py", line 73, in get_display
    return mod.get_display(display)
  File "/Users/VemPC/Desktop/Challenges/venv/lib/python3.7/site-packages/Xlib/support/unix_connect.py", line 61, in get_display
    raise error.DisplayNameError(display)
Xlib.error.DisplayNameError: Bad display name ""

pyxhook seems to be a linux specific library. Specifically, it is an implementation of PyHook for linux, using X, the window system library. MacOS provides some support for this, but not all, as MacOS is not built on X. It seems like you won't be able to use this library on your system.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM