curses problem reading cursor keys

S

Simon Morgan

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)
 
S

Simon Morgan

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()

If I use scr.subwin() instead of curses.newwin()...
y = 0
while True:
c = list.getch()

and scr.getch() instead of list.getch(), things seem to work. I'd still
really like to know what's going on though.
 
R

Rainy

Simon said:
If I use scr.subwin() instead of curses.newwin()...


and scr.getch() instead of list.getch(), things seem to work. I'd still
really like to know what's going on though.

I don't have a linux here now but I vaguely remember running into this.
I think what I did was just writing down what code you do get when
pressing down and up, etc, and using that code. By the way I looked
around back then and didn't find any thorough tutorials on curses,
either.
 
T

Thomas Dickey

Simon Morgan said:
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.

esr only contributed his name - awk wrote the rest.
(When I asked why, he only said it sounded like a good idea ;-)
 

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

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top