在下面的 doDebuggingMenu 函数中,我使用 raw_input 函数(使用 Python 2.6)获取用户输入。这个函数一直等到用户输入一个字符序列并按下回车键。尽管如此,我希望用户只需按下键盘上的 ESC 按钮即可退出应用程序,而不必按 Enter(请参阅我打算实现此行为的函数中的最后一个 elif 块)。对于其他菜单选项,用户应该能够按下回车按钮,因为菜单中有需要输入两位数字的选项。我的问题是如何在以下函数中提供这种组合行为?谢谢
def doDebugingMenu():
while(1):
printDebugingMenu()
char = raw_input("\nPlease, enter your selection in the debugging menu...:")
if char == '1':
doSetTraceLevelManually()
elif char == '2':
doSetTraceDomain()
elif char == '3':
doPrintLevels()
elif char == '4':
doPrintConfig()
elif char == '5':
doPrintProfile()
elif char == '6':
doPrintMap()
elif char == '7':
doPrintCounters()
elif(char == '8'):
doRaiseAlarm()
elif(char == '9'):
doClearAlarm()
elif(char == '10'):
doUpdateAlarm()
elif(char == '11'):
doShutdown()
#HERE I need to catch if ESC pressed
elif char == 'ESC':
break
def printDebugingMenu():
print "\n######################################"
print "# MENU #"
print "######################################"
print "1. setTraceLevel( traceLevel )"
print "2. setTraceDomain()"
print "3. PRINT Trace Domain and levels"
print "4. PRINT config"
print "5. PRINT profile config"
print "6. PRINT mapping config"
print "7. PRINT counters"
print "8. Issue Alarm"
print "9. Remove Alarm"
print "10. Update Alarm"
print "11. Shutdown"
print "EXIT: press ESC"