~clicompanion-devs/clicompanion/clicomp-glade

« back to all changes in this revision

Viewing changes to comps.drafts.builds/KeyLogger.py

  • Committer: duanedesign
  • Date: 2010-04-04 05:50:48 UTC
  • Revision ID: duanedesign@gmail.com-20100404055048-hqptxm1na56lawe6
"added scroling, 56 command capacity"

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# KeyLogger_tk2.py
 
2
# show a character <strong class="highlight">key</strong> when pressed without using Enter <strong class="highlight">key</strong>
 
3
# hide the Tkinter GUI window, only console shows
 
4
 
 
5
try:
 
6
    # Python2
 
7
    import Tkinter as tk
 
8
except ImportError:
 
9
    # Python3
 
10
    import tkinter as tk
 
11
 
 
12
def key(event):
 
13
    """shows <strong class="highlight">key</strong> or tk code for the <strong class="highlight">key</strong>"""
 
14
    if event.keysym == 'Escape':
 
15
        root.destroy()
 
16
    if event.char == event.keysym:
 
17
        # normal number and letter characters
 
18
        print( 'Normal Key %r' % event.char )
 
19
    elif len(event.char) == 1:
 
20
        # charcters like []/.,><#$ also Return and ctrl/key
 
21
        print( 'Punctuation Key %r (%r)' % (event.keysym, event.char) )
 
22
    else:
 
23
        # f1 to f12, shift keys, caps lock, Home, End, Delete ...
 
24
        print( 'Special Key %r' % event.keysym )
 
25
 
 
26
 
 
27
root = tk.Tk()
 
28
print( "Press a key (Escape key to exit):" )
 
29
root.bind_all('<Key>',key)
 
30
# don't show the tk window
 
31
root.withdraw()
 
32
root.mainloop()