curses getch() returns different values for the main window and pads in python

StackOverflow https://stackoverflow.com/questions/12762496

  •  05-07-2021
  •  | 
  •  

سؤال

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)
هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top