简体   繁体   English

如何在python中检测curses ALT +组合键

[英]How to detect curses ALT + key combinations in python

New to python here and using the curses import. 这里是python的新手,并使用curses导入。 I want to detect key combinations like ALT + F and similar. 我想检测像ALT + F和类似的关键组合。 Currently, I am using getch() to receive a key and then printing it in a curses window. 目前,我使用getch()接收密钥,然后在curses窗口中打印它。 The value does not change for F or ALT + F . FALT + F的值不会改变。 How can I detect the ALT key combinations? 如何检测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)

Try this: 尝试这个:

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM