没有属性"HookManager" [英] No attribute 'HookManager'

查看:298
本文介绍了没有属性"HookManager"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在复制此视频中的按键记录器:( https://www.youtube.com/watch?v = 8BiOPBsXh0g )并运行代码:

I am copying the key logger from this video: (https://www.youtube.com/watch?v=8BiOPBsXh0g) and running the code:

    import pyHook, sys, logging, pythoncom

    file_log = 'C:\Users\User\Google Drive\Python'

    def OnKeyboardEvent(event):
        logging.basicConfig(filename = file_log, level = logging.DEBUG, format = '%(message)s')
        chr(event.Ascii)
        logging.log(10, chr(event.Ascii))
        return True

    hooks_manager = pyHook.HookManager()
    hooks_manager.KeyDown = OnKeyboardEvent
    hooks_manager.HookKeyboard()
    pythoncom.Pumpmessages()

这将返回错误:

    Traceback (most recent call last):
      File "C:\Users\User\Google Drive\Python\pyHook.py", line 2, in  <module>
        import pyHook, sys, logging, pythoncom
      File "C:\Users\User\Google Drive\Python\pyHook.py", line 12, in <module>
        hooks_manager = pyHook.HookManager()
    AttributeError: 'module' object has no attribute 'HookManager'

我正在运行Python 2.7.11和Windows计算机. 我不知道问题出在哪里;请帮忙. 谢谢

I am running Python 2.7.11 and a windows computer. I don't know what the problem is; please help. Thank you

推荐答案

我仍然不确定问题出在哪里,但我找到了解决方案. 如果您移动程序,则尝试将其运行到与HookManager.py文件相同的文件夹中,然后它将起作用.

I'm still unsure what the issue is but I found a solution. If you move the program you are trying to run into the same folder as the HookManager.py file then it works.

对我来说,这个文件是: C:\ Python27 \ Lib \ site-packages \ pyHook

For me this file was: C:\Python27\Lib\site-packages\pyHook

这篇关于没有属性"HookManager"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆