Skip to content Skip to sidebar Skip to footer

Curses Print Characters As Typed

Using python I am wanting to have the characters printed out as i type, this is easy in java script, but I am not understanding how to use the curses module, this is the code that

Solution 1:

If you just want to get the user input and make the characters printed out as they are typed, there's not much to do :

import          curses

stdScr = curses.initscr()
myInput = stdScr.getstr()
curses.endwin()
print(myInput.decode('utf-8'))

Here, you just initialize the curses module by calling curses.initscr(). It gives you the stdScr and you just have to call the getstr() method of stdScr (which is actually a curses.window object) which will give you the user input printing the characters as they are typed.

I don't know if you've already checked this out, but it's very clear : http://docs.python.org/3.3/library/curses.html

Have fun ! (curses is an awesome module !)

Post a Comment for "Curses Print Characters As Typed"