By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,199 Members | 1,064 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,199 IT Pros & Developers. It's quick & easy.

curses problem reading cursor keys

P: n/a
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)
Oct 7 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Sat, 07 Oct 2006 13:12:33 +0000, Simon Morgan wrote:
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.
if c in (curses.KEY_UP, curses.KEY_DOWN, ord('z')):
list.addstr("Match!")
elif c == ord('q'):
break

curses.wrapper(main)
Oct 7 '06 #2

P: n/a

Simon Morgan wrote:
On Sat, 07 Oct 2006 13:12:33 +0000, Simon Morgan wrote:
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.
if c in (curses.KEY_UP, curses.KEY_DOWN, ord('z')):
list.addstr("Match!")
elif c == ord('q'):
break

curses.wrapper(main)
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.

Oct 7 '06 #3

P: n/a
Simon Morgan <me@privacy.netwrote:
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 ;-)

--
Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net
Oct 11 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.