2011-05-12 52 views
12

我有一个问题,NCURSES ...我需要处理像Esc键Alt键 + ˚F等 问题是,代码是相似的所有键.. 。即:NCURSES和ESC,ALT键


Esc键 - 27


Alt键 + - 27 65


作为一个例子存在用于Alt键 + [键]组合什么类似Esc键键... 任何双码想法如何处理?

回答

7

通过解决:

  1. 使用NOECHO或超时模式
  2. 检查27(ALT或ESC)的代码......如果通:
  3. 尝试,如果另一个代码读取另一个代码
  4. 是ERR然后..你有ESC键以其他方式你有ALT +另一个代码
+0

如果用户点击“ESC”,然后再选择另一个键,比如'['',例如,一个接一个很快,我们的代码不能看到两个键都会通过,然后它不会看起来像' ESC'_?因为我真的不知道终端会如何知道在我第二次打电话时想要收集下一个字符,我试图确定是否只是“ESC”被击中了?! – 2018-01-16 05:24:46

12

这里是一个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)