def get_input():
global lines
data = None
try:
if sys.platform in ['linux', 'darwin']:
import select
time.sleep(0.01)
if select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], []):
data = sys.stdin.readline().rstrip()
elif sys.platform == 'win32':
import msvcrt
time.sleep(0.01)
if msvcrt.kbhit():
data = msvcrt.getch().decode('utf-8')
if data == '\r':
# Enter is pressed
data = lines
lines = ''
else:
lines += data
print(data)
data = None
else:
pass
except KeyboardInterrupt:
data = 'exit'
return data
评论列表
文章目录