''' tk_KeyLogger.py
show any character/special key when pressed
using Tkinter
'''

try:
    # Python2
    import Tkinter as tk
except ImportError:
    # Python3
    import tkinter as tk

def show_key(event):
    '''show event.keycode, event.keysym, event.char results'''
    if event.char == event.keysym:
        msg = 'Normal Key %r' % event.char
    elif len(event.char) == 1:
        msg = 'Punctuation Key %r (%r)' % (event.keysym, event.char)
    else:
        msg = 'Special Key %r' % event.keysym
    print(msg)
    if event.keysym == 'Escape':
        root.destroy()

root = tk.Tk()
print("Press a key (Escape key to exit): ")
root.bind_all('<Key>', show_key)
# don't show the tk window
root.withdraw()
root.mainloop()

And the purpose of this is? Keyloggers can be used to build a remote-control support application (I have done so in the past, and that is what VNC and other RC applications do), or it can be used for nefarious purposes. In any case, it can be a dangerous path to provide for those who don't know how to pwn systems already... :-(

Thank's a lot!
That was exactly what I needed.
The only issue I havn't discovered is, why it doesn't work on my RasPi
if I hide the root-window via root.withdraw. If I show it, the code works properly.

some ideas?

best regards

Andy

The article starter has earned a lot of community kudos, and such articles offer a bounty for quality replies.