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

M

malahal

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top