from pynput.keyboard import Listener
from datetime import datetime
def on_press(key):
key = str(key).replace("Key.", "").replace("'", "")
if len(key) > 1:
key = key.upper()
print (datetime.now().strftime("%Y-%m-%d %H:%M:%S") + " " + key)
with Listener(on_press=on_press) as listener:
listener.join()