Curses & Keypress

A

ale.of.ginger

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 (keypressvariable == 'numpad7'):
WConio.gotoxy(x-1,y+1)

etc...

Thanks.
 
L

Lee Harr

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 (keypressvariable == 'numpad7'):
WConio.gotoxy(x-1,y+1)




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(10, 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('test:', 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.
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top