Skip to content

Instantly share code, notes, and snippets.

@nattybear
Last active June 7, 2017 17:43
Show Gist options
  • Save nattybear/d392cc769c9fc92a90600d0c0183e7cb to your computer and use it in GitHub Desktop.
Save nattybear/d392cc769c9fc92a90600d0c0183e7cb to your computer and use it in GitHub Desktop.
# KeyLogger_tk2.py
# show a character key when pressed without using Enter key
# hide the Tkinter GUI window, only console shows
# Python3
import Tkinter as tk
def key(event):
'''shows key or tk code for the key'''
if event.keysym = 'Escape':
root.destroy()
if event.char == event.keysym:
# normal number and letter characters
print('Normal key %r' % event.char)
elif len(evnet.char) == 1:
# charcters like []/.,><#$ also Return and ctrl/key
print('Puctuation Key %r (%r)' % (event.keysym, event.char) )
else:
# f1 to f12, shift keys, caps lock, Home, End, Delete ...
print('Special Key %r' % event.keysym)
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment