Curses & Keypress

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ale.of.ginger@gmail.com

    #1

    Curses & Keypress

    Now that I have gotoxy() down for moving the cursor around, I want that
    to be a result of keypresses (namely from the numpad -- 7 = NorthWest,
    8 = North, 9 = NE, etc...). I have little clue how to do this. After
    searching google, I've come upon this; include:

    import curses

    in the header. However, I've found various methods of actually reading
    the keyboard press (getch(), raw_input, etc.). What is the best method
    to use for reading keypress, so I can have something like:

    if (keypressvariab le == 'numpad7'):
    WConio.gotoxy(x-1,y+1)

    etc...

    Thanks.

  • Lee Harr

    #2
    Re: Curses & Keypress

    On 2005-11-11, ale.of.ginger@g mail.com <ale.of.ginger@ gmail.com> wrote:[color=blue]
    > Now that I have gotoxy() down for moving the cursor around, I want that
    > to be a result of keypresses (namely from the numpad -- 7 = NorthWest,
    > 8 = North, 9 = NE, etc...). I have little clue how to do this. After
    > searching google, I've come upon this; include:
    >
    > import curses
    >
    > in the header. However, I've found various methods of actually reading
    > the keyboard press (getch(), raw_input, etc.). What is the best method
    > to use for reading keypress, so I can have something like:
    >
    > if (keypressvariab le == 'numpad7'):
    > WConio.gotoxy(x-1,y+1)
    >[/color]




    Here is a little snip that shows how I do this:


    #
    import curses

    class TestScreen:
    def __init__(self, scr):
    self.scr = scr
    self.scr.move(1 0, 5)
    self.scr.addstr ('Press q to QUIT', curses.A_BOLD)


    def loop(self):
    k = None
    while k != 'q':
    k = self.scr.getkey ()
    try:
    o = ord(k)
    except:
    o = '????'
    #Error.elog('te st:', k, o)

    def test_keys(scr):
    screen = TestScreen(scr)
    screen.loop()

    if __name__ == '__main__':
    curses.wrapper( test_keys)
    #



    Not on windows, though. So I do not know if this
    will work for you at all.

    The .elog thing is a function I wrote for testing
    curses apps. Since the console is busy, you can't
    usefully print to stdout. So .elog just feeds its
    arguments to a log file.

    I found the trickiest part is that the keyboard
    scan codes are all over the place. Two systems
    that are identical in every other way might give
    two different results when pressing a key.

    Comment

    Working...