-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
39 lines (32 loc) · 915 Bytes
/
test.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
37
38
39
from key_getter import KeyGetter
import time
def test1(): # Test with block=False
print('test1')
k = KeyGetter()
try:
while True:
if k.kbhit():
print('Got', repr(k.getch(False)))
print('Got', repr(k.getch(False)))
else:
print('Nothing')
time.sleep(0.5)
except KeyboardInterrupt:
pass
print(input('Enter something:'))
def test2(): # Test context manager with block=True
print('test2')
with KeyGetter() as k:
try:
while True:
if k.kbhit():
print('Got', repr(k.getchar(True)))
print('Got', repr(k.getchar(True)))
else:
print('Nothing')
time.sleep(0.5)
except KeyboardInterrupt:
pass
print(input('Enter something:'))
test1()
test2()