-4

I followed a tutorial on youtube that was pretty flawed to begin with but it was the best I could find. I have pywin32 installed and pyhook and they are both installed so I have no idea what it could be.

   import pyHook, pythoncom, sys, logging

file_log = 'C:\Users\Nathan\Fun Stuff\log.txt'

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

hooks_manager = pyHook.HookManager()
hooks_manager.KeyDown = OnKeyboardEvent
hooks_manager.HookKeyboard()
pythoncom.PumpMessages()
Addison Land
  • 1
  • 1
  • 1
  • 1
    Please see [How to Ask](http://stackoverflow.com/help/how-to-ask). You need to provide us with the error you are getting, as well as tell us what you have tried to fix the issue. – stelioslogothetis May 11 '17 at 20:35
  • The error was "value error incomplete format" on line 8 so I put an equal sign and it no longer shows the error but its still not working properly its supposed to log all of my key presses into a log.txt but the log file is not sowing anything – Addison Land May 11 '17 at 20:50

1 Answers1

5

"format" refers to the "%(message)" which is incomplete and should read "%(message)s", the s denoting a "str conversion type" (see the docs) - the message is put through the str builtin.

"$(message)s" happens to be default, I think you can just omit this argument.

tiwo
  • 3,238
  • 1
  • 20
  • 33
  • I am no longer getting the format error but at this point its not logging the key presses into the log.txt file like it should – Addison Land May 11 '17 at 20:58