Unable to find the ] or } characters using python curses and Getch

95 views Asked by At

I have a very basic program which takes a character from the user and prints it back on screen. This works for every key except for the ]} key. This key returns 0 from the getch call. I have no explanation or this or why it would happen. I would blame my computer's specific key if not for the fact that I tried on another computer and had the same issue. I am on windows if that is important. The code is below. I am unable to find another person having this issue so I am sure I am making somedumb mistake but for the life of me can not find it.

import curses
 
# get the curses screen window
screen = curses.initscr()
 
# turn off input echoing
curses.noecho()
 
# respond to keys immediately (don't wait for enter)
curses.cbreak()
 
# map arrow keys to special values
screen.keypad(True)
 
try:
    while True:
        char = screen.getch()
        if char == ord('q'):
            break
        else:
            screen.move(0, 0)
            screen.clrtoeol()
            screen.addstr(0, 0, chr(char))
finally:
    # shut down cleanly
    curses.nocbreak(); screen.keypad(0); curses.echo()
    curses.endwin()

I tried to type the }] key, both with an without shift. I expected that output to be reflected on screen. Instead it throws an error since it can't print the null character of 0 that it thinks it is getting. Any advice helps

0

There are 0 answers