[Tutor] curses, key controls ?

djuro dmandini at inet.hr
Tue Jan 20 17:44:58 EST 2004



Hello!

I am beginner and I'm trying to write simple program in curses but this is 
what confuses me:
How to end this iteration by pressing a certain key, for instance ESC or "q"??

getchar() delays execution and waits for user input, nodelay() breaks when ANY
key is pressed. 
I need a way to specify a certain key for termination.

#######################################
import curses, time

stdscr = curses.initscr()
curses.noecho()
curses.cbreak()
stdscr.keypad(1)

# next f. displays time at given coords. 
# and refreshes after each second 

def dsply_time():       
        t = time.time()
        t = str(t)
        stdscr.addstr(2,2,t)
        stdscr.refresh()
        time.sleep(1)
        dsply_time()

dsply_time()


curses.nocbreak(); stdscr.keypad(0); curses.echo()
curses.endwin()
################################################

Thank you



More information about the Tutor mailing list