0

I am trying to get user input in curses (python), and for some reason it cannot detect when I press the ENTER key.

while True:
        key = stdscr.getkey()
        if key == curses.KEY_ENTER:
            TASK += 1
            break
        elif key.lower() == 'q':
            quit(stdscr)
            break

the if part is not working and the elif part is working fine.

  • 2
    This answers your question: [Interpreting "ENTER" keypress in stdscr (curses module in Python)](https://stackoverflow.com/questions/32252733/interpreting-enter-keypress-in-stdscr-curses-module-in-python) – Thomas Dickey Feb 07 '22 at 08:38

1 Answers1

0

curses.KEY_ENTER would be the numeric-keypad Enter key

  • if curses keypad mode is enabled and
  • if the terminal description has the corresponding code and
  • if the terminal actually sends what the terminal description says. (Keypad coverage on some terminal emulators is an area for improvement).

It's not related to the Enter key on the main keyboard.

You'll get better results if you add a comparison for \n and \r (this is probably a duplicate).

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105