curses problem reading cursor keys

Simon Morgan me at privacy.net
Sat Oct 7 15:12:33 CEST 2006


Hi,

I'm having trouble with the following code. The problem is that the value
read by getch() when I hit the up or down keys doesn't match curses.KEY_UP
or curses.KEY_DOWN respectively. Other keys, such as 'z' in my example
code, work fine.

I only seem to have this problem when dealing with newly created windows
and not with the standard/default/root one created by curses.wrapper() and
passed to main().

I'd also appreciate any pointers to good tutorials on curses, I've read
the one by awk and esr but found it rather brief and lacking in detail.

Thanks.

import curses

def main(scr):
    status = curses.newwin(1, curses.COLS, 0, 0) status.bkgd('0')
    status.refresh()

    list = curses.newwin(curses.LINES, curses.COLS, 1, 0) list.bkgd('X')
    list.refresh()

    y = 0
    while True:
        c = list.getch()
        if c in (curses.KEY_UP, curses.KEY_DOWN, ord('z')):
            list.addstr("Match!")
        elif c == ord('q'):
            break

curses.wrapper(main)



More information about the Python-list mailing list