2
Contributors
3
Replies
22
Views
3 Years
Discussion Span
Last Post by NITHIN171
0

This will do it ...

# tk_KeyLogger.py
# show a character key when pressed

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

def key(event):
    """show just the character key"""
    if event.keysym == 'Escape':
        root.destroy()
    print(event.char)

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

Edited by vegaseat

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.