1

I am developing one app in python curses. I am using getch() method to get pressed keys. But I can see pressed keys on screen. I can move cursor whenever I want, but after cursor I can see what user typed.

Of course, I can erase and redraw the whole screen after every pressed key, but it's blinking - that's distrubing.

Any idea how to get rid of these pressed keys? Thank you

4
  • possible duplicate of Can i get console input without echo in python? Commented Jun 13, 2012 at 22:37
  • 1
    I am using curses. Not standard terminal input. Commented Jun 13, 2012 at 22:40
  • Ah, I see. However, the same techniques used in getpass might help in your situation too. It would be worth looking at, I think. Commented Jun 13, 2012 at 22:42
  • I hope, there is some solution, built in curses ;) Commented Jun 13, 2012 at 22:53

1 Answer 1

4

Initialize the curses class in the following way, it will solve the problem.

class curses_screen:
    def __enter__(self):
        self.stdscr = curses.initscr()
        curses.cbreak()
        curses.noecho()
        self.stdscr.keypad(1)
        SCREEN_HEIGHT, SCREEN_WIDTH = self.stdscr.getmaxyx()
        return self.stdscr
    def __exit__(self,a,b,c):
        curses.nocbreak()
        self.stdscr.keypad(0)
        curses.echo()
        curses.endwin()

with curses_screen() as stdscr:
    """
    Execution code plush getch code here
    """
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, cbreak() and noecho() is what I wanted ;) Thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.