Python Getch在调用之前获取输入
我正在用python编写一个curses应用程序Python Getch在调用之前获取输入,python,python-curses,Python,Python Curses,我正在用python编写一个curses应用程序 def main(stdscr): stuff(stdscr) def printStuff(stdscr, string): stdscr.clear() stdscr.addstr(0, 0, string) stdscr.refresh() def stuff(stdscr): printStuff(stdscr, 'foo') time.sleep(3) printStuff(s
def main(stdscr):
stuff(stdscr)
def printStuff(stdscr, string):
stdscr.clear()
stdscr.addstr(0, 0, string)
stdscr.refresh()
def stuff(stdscr):
printStuff(stdscr, 'foo')
time.sleep(3)
printStuff(stdscr, 'bar')
stdscr.getch()
wrapper(main)
当我运行代码时,大部分情况下一切都很好。
如果我在睡眠时在三秒钟的间隔内按下一个按钮,getch将很乐意将其作为输入,即使在调用getch之前按下了该按钮。这是为什么?我如何解决这个问题?输入是缓冲的,
getch()
处理输入缓冲区中的任何内容。您可以使用清除缓冲区
输入被缓冲,并且
getch()
处理输入缓冲区中的任何内容。您可以使用清除缓冲区
您所做的一切都被放入一个输入队列
getch
处理队列中的任何内容。您所做的一切都被放入一个输入队列getch
处理队列中的任何内容。
def stuff(stdscr):
printStuff(stdscr, 'foo')
time.sleep(3)
printStuff(stdscr, 'bar')
stdscr.flushinp()
stdscr.getch()