curses problem reading cursor keys

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Simon Morgan

    #1

    curses problem reading cursor keys

    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(c urses.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("Ma tch!")
    elif c == ord('q'):
    break

    curses.wrapper( main)
  • Simon Morgan

    #2
    Re: curses problem reading cursor keys

    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(c urses.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("Ma tch!")
    elif c == ord('q'):
    break
    >
    curses.wrapper( main)

    Comment

    • Rainy

      #3
      Re: curses problem reading cursor keys


      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(c urses.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("Ma tch!")
      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.

      Comment

      • Thomas Dickey

        #4
        Re: curses problem reading cursor keys

        Simon Morgan <me@privacy.net wrote:
        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
        Thomas Dickey develops/maintains widely-used tools and libraries for software development (diffstat, yacc, mawk) and terminals (ncurses, lynx, xterm)

        ftp://invisible-island.net

        Comment

        Working...