在 Python模块中,我观察到按键和返回curses
之间大约有 1 秒的延迟。其他键似乎不会出现这种延迟。为什么会发生这种情况,我该怎么办?escgetch()
测试用例:
import curses
import time
def get_delay(window, key):
while True:
start = time.time()
ch = window.getch()
end = time.time()
if ch == key:
return end-start
def main(stdscr):
stdscr.clear()
stdscr.nodelay(1)
stdscr.addstr("Press ESC")
esc_delay = get_delay(stdscr, 27)
stdscr.addstr("\nPress SPACE")
space_delay = get_delay(stdscr, ord(' '))
return esc_delay, space_delay
if __name__ == '__main__':
esc_delay, space_delay = curses.wrapper(main)
print("Escape delay: {} ms".format(esc_delay*1000))
print("Space delay: {} ms".format(space_delay*1000))
结果:
Escape delay: 1001.09195709 ms
Space delay: 0.00596046447754 ms