[英]python curses not recognizing arrow keys
i have this simple program.我有这个简单的程序。 there is no error in the program also the when i press q the program exits
程序中也没有错误,当我按 q 时程序退出
import curses
def main(stdscr):
while 1:
Key = stdscr.getch()
if Key == curses.KEY_UP:
stdscr.addstr(0,0,'u pressed up key ')
stdscr.refresh()
elif Key == curses.KEY_DOWN:
stdscr.addstr(0,0,'u pressed down key')
stdscr.refresh()
elif Key == curses.KEY_LEFT:
stdscr.addstr(0,0,'u pressed left key')
stdscr.refresh()
elif Key == curses.KEY_RIGHT:
stdscr.addstr(0,0,'u pressed right key')
stdscr.refresh()
elif Key == ord('q'):
break
curses.wrapper(main)
If getkey
on arrow keys is giving you letters {A|B|C|D} and getch
is giving your their numeric equivalents, call .keypad(True)
on the window from which you're reading.如果箭头键上的
getkey
给你字母 {A|B|C|D} 而getch
给你他们的数字等价物,请在你正在阅读的 window 上调用.keypad(True)
。 doc 文件
stdscr.keypad(True)
key = stdscr.getch()
stdscr.addstr(0, 0, '%s' % key == curses.KEY_UP)
This will have curses interpret the arrow keys' entire escape sequence for you.这将使 curses 为您解释箭头键的整个转义序列。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.