Why does the escape key have a delay in Python curses?

眉间皱痕 提交于 2019-12-05 01:36:43

In order to customize the Esc delay you can set the environment variable ESCDELAY which curses uses to determine the time in milliseconds it waits before it delivers the Escape Key.

In order to define this variable in Python you could for example call the following function prior to your call to curses.wrapper(main):

def set_shorter_esc_delay_in_os():
    os.environ.setdefault('ESCDELAY', '25')

which will set the environment variable to 25ms if it has not been set before.

See also the man page of ncurses (search for ESCDELAY).

Curses deals with "escape sequence"s from your terminal to represent commands to the software These sequences normally begin with an escape character. Consequently, when you hit ESC the curses code doesn't emit anything immediately in case this represents the start of an escape sequence.

ESCDELAY=25 ...put this in global.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!