-
Notifications
You must be signed in to change notification settings - Fork 1
/
keyevent.py
36 lines (34 loc) · 842 Bytes
/
keyevent.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import curses
def main(win):
win.nodelay(True)
win.keypad(True)
key=""
win.clear()
win.addstr("Detected key:")
last_key = None
counter = 0
done = False
while done == False:
try:
key = win.getch()
if key == -1:
# No input
continue
win.clear()
win.addstr("Detected key:")
win.addstr(str(key))
if key == last_key:
counter += 1
else:
counter = 0
last_key = key
win.addstr(" ({})".format(counter))
if key == 27: # push ESC key
done = True
break
else:
win.refresh()
except Exception as e:
# No input
pass
curses.wrapper(main)