NCurses和ESC,ALT键

时间:2011-05-12 11:41:26

标签: key ncurses

我有 NCurses 的问题...我需要处理所有键,例如 Esc Alt + F 等 问题是代码是相似的......即:


Esc - 27


Alt + A - 27 65


作为示例, Alt + [key] 组合的双重代码类似 Esc 键的组合... 任何想法如何处理?

3 个答案:

答案 0 :(得分:15)

这是python的一个例子:

key = self.screen.getch()
if key == ord('q'): # quit
    go = False
elif key == 27: # Esc or Alt
    # Don't wait for another key
    # If it was Alt then curses has already sent the other key
    # otherwise -1 is sent (Escape)
    self.screen.nodelay(True)
    n = self.screen.getch()
    if n == -1:
        # Escape was pressed
        go = False
    # Return to delay
    self.screen.nodelay(False)

答案 1 :(得分:7)

解决方案:

  1. 使用noecho或超时模式
  2. 检查27( ALT ESC )代码...如果通过:
  3. 尝试阅读其他代码
  4. 如果另一个代码是ERR那么..你有 ESC 键以其他方式你有 ALT +另一个代码

答案 2 :(得分:0)