[Tutor] Re: getting input from keyboard

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Tue Dec 24 14:38:11 2002


On Tue, 24 Dec 2002, Derrick 'dman' Hudson wrote:

> On Mon, Dec 23, 2002 at 09:33:41PM -0800, Tony Cappellini wrote:
> |
> | How do I get keyboard input in python ?
> | I want to do the equivalent of this C code, in python
> |
> | x=getch()
>
> The raw_input() function obtains input from the program's stdin (which
> will be the keyboard unless you use IO redirection).
>
> If you are running python on windows, you can import the 'mswin' (or
> somesuch) and obtain a function named getch().

Hello!

I've written a small Cookbook recipe to make using getch() somewhat
simpler:

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

It should work on Windows and Unix platforms; I hope it works for you.


Happy holidays!