unbuffered input

Gerrit gerrit at nl.linux.org
Thu Feb 5 15:28:04 EST 2004


michael young wrote:
>   I have a numbered menu that I want users to from. They choose the
> number corresponding to the action they wish to take.
> Right now I'm using input() to get the user's responce. They press the
> number then press ENTER. I would like to skip the
> part where they press ENTER, so that the user presses the number and
> then they get the action they chose without having
> to press ENTER. Is there a way to do this and how?

Yes, but it's not really platform-independent.
You can find a way to do this at:

    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/134892

On Windows, you can use the getch() function from the mscvrt module.
On Unix, it is a bit more difficult, but the trick is using tty.setraw.
On Mac, you use the Carbon package.

Gerrit.

-- 
PrePEP: Builtin path type
    http://people.nl.linux.org/~gerrit/creaties/path/pep-xxxx.html
Asperger's Syndrome - a personal approach:
	http://people.nl.linux.org/~gerrit/english/




More information about the Python-list mailing list