in ebcli/display/term.py [0:0]
def inkey(self, timeout=None):
# Since get_key is a single method, we will just do the cbreak
# and input stuff in a single method.
# We should ever need inkey without cbreak
if sys.version_info[0] >= 3:
from msvcrt import kbhit, getwch as _getch
else:
from msvcrt import kbhit, getch as _getch
def readInput():
start_time = time.time()
while True:
if kbhit():
return _getch()
if (time.time() - start_time) > timeout:
return None
key = readInput()
if not key:
return None
if key == '\x03':
# Ctrl C
raise CaughtSignal(2, None)
elif key == '\x1c':
# Ctrl \
sys.exit(1)
elif key == '\xe0':
# Its an arrow key, get next symbol
next_key = _getch()
if next_key == 'H':
return Val(name='KEY_UP', code=259)
elif next_key == 'K':
return Val(name='KEY_LEFT', code=260)
elif next_key == 'P':
return Val(name='KEY_DOWN', code=258)
elif next_key == 'M':
return Val(name='KEY_RIGHT', code=261)
elif key == '\x1b':
return Val(name='KEY_ESCAPE', code=361)
elif key == '\x0d':
return Val(name='KEY_ENTER', code=362)
else:
return Val(key=key)