python script reading special keys like <F1>, <F2> etc.

malahal at us.ibm.com malahal at us.ibm.com
Mon Jul 17 22:28:09 EDT 2006


I am planning to write a very simple python script that displays files
based on user input. E.g. I need to display f1.msg file if the user
presses <F1> key, f2.msg file if the user presses <F2> key.  What is the
easiest way to do this on Linux (xterm/vt100/asni etc).  I tried using
curses and it works, but I want something that does NOT modify or redraw
the user screen.

Something like this:
def display():
    key = raw_input()
    if key == <F1>
        sys.stdout.write(open(f1.msg, "r").read())
    elif key == <F2>
        sys.stdout.write(open(f2.msg, "r").read())
    else: # I need to capture his input string too.
        return key


I can make a restriction that the user press <Enter> after typing the
above keys if required. Is there a solution that doesn't redraw the
screen like curses does and kind of portable at the same time to
different terminals on Linux/Unix?



More information about the Python-list mailing list