Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7807813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:58:18+00:00 2026-06-02T02:58:18+00:00

In the doDebuggingMenu function below, I am getting the user input using the raw_input

  • 0

In the doDebuggingMenu function below, I am getting the user input using the raw_input function (using Python 2.6). This function waits until the user enters a char sequence and presses enter. Neverthless, I would like to allow the user to exit the application by simply pressing the ESC button in the keyboard without having to press enter (Please see the last elif block in the function where I intend to implement this behaviour). For other menu options the user should be able to press the enter button because there are options in the menu that requires entering a two digit number. My question here is how can I provide this combined behaviour in the following function? Thanks

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"
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T02:58:21+00:00Added an answer on June 2, 2026 at 2:58 am

    raw_input() is not what you need.

    You need to process input character by character so you can detect ESC, function keys, etc. Maybe build your own input function that returns the text when you press ENTER but throws exceptions on other keys, but then you need to process backspaces, cursor movements, etc. You can find primitives in the curses module on Unices or msvcrt on Windows. It’s a lot of work. But then you have it and it’s reusable if you are writing lots of console based programs.

    Normally, though, users are quite content to just use Ctrl-C if they want to exit the program and there is no need to complicate things. If you want something fancy write a GUI program. Up to you.

    On a side note, that if … elif … elif block looks horribly non-pythonic. Take a look at this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.