curses getch() returns different values for the main window and pads in python
Question
The getch()
method returns different values for the main window and pads if the key pressed is non-ASCII. For example, pressing the arrow keys I get the expected KEY_UP
, KEY_DOWN
etc in the main window, but in the pad I get 65
for the up arrow and 66
for the down arrow. Why is this, and is there a way to get larger than 255 values for special keys in a pad?
I am using Python 2.6.5.
The following code demonstrates the issue:
import curses
def main(stdscr):
c = None
while c != curses.KEY_RIGHT:
c = stdscr.getch()
stdscr.addstr(0, 0, "%3d" % c)
stdscr.refresh()
pad = curses.newpad(20, 20)
while True:
c = pad.getch()
pad.addstr(0, 0, "%3d" % c)
pad.refresh(0, 0, 1, 0, 20, 20)
if __name__ == '__main__':
curses.wrapper(main)
La solution
Did you try
pad.keypad(1)
This is the first time I need to deal with curses in Python, and I had the same problem this morning.
Autres conseils
I don't have a direct answer to your question, but I do observe that 65 and 66 are the ASCII values of 'A' and 'B', which happen to be the CSI or SS3 commands used by the Up and Down arrow.