这里是python的新手,并使用curses导入。我想检测关键组合,如 ALT + F 等。目前,我使用getch()
接收密钥,然后在curses窗口中打印它。 F 或 ALT + F 的值不会改变。如何检测 ALT 组合键?
import curses
def Main(screen):
foo = 0
while foo == 0:
ch = screen.getch()
screen.addstr (5, 5, str(ch), curses.A_REVERSE)
screen.refresh()
if ch == ord('q'):
foo = 1
curses.wrapper(Main)
答案 0 :(得分:3)
试试这个:
import curses
def Main(screen):
while True:
ch = screen.getch()
if ch == ord('q'):
break
elif ch == 27: # ALT was pressed
screen.nodelay(True)
ch2 = screen.getch() # get the key pressed after ALT
if ch2 == -1:
break
else:
screen.addstr(5, 5, 'ALT+'+str(ch2))
screen.refresh()
screen.nodelay(False)
curses.wrapper(Main)