[Tutor] Re: getting input from keyboard

Derrick 'dman' Hudson dman@dman.ddts.net
Tue Dec 24 01:02:02 2002


--gKMricLos+KVdGMg
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Mon, Dec 23, 2002 at 09:33:41PM -0800, Tony Cappellini wrote:
|=20
| How do I get keyboard input in python ?
| I want to do the equivalent of this C code, in python
|=20
| x=3Dgetch()

That isn't a standard C library function.  It is, I belive, a Borland
(or maybe a Microsoft) extension.  UNIX systems don't normally have
that function, since the intput to a program may or may not be
connected to a keyboard.

| With the books that I have, there are no references in the index  to get,=
=20
| keyboard input, or in the Python help file.
|=20
| What is the magic word I am looking for ?

That depends.

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().

If you want to react to just a single keystroke (rather than
line-buffered input) and be mostly cross-platform, use the ncurses
library.

HTH,
-D

--=20
Pride only breeds quarrels,
but wisdom is found in those who take advice.
        Proverbs 13:10
=20
http://dman.ddts.net/~dman/

--gKMricLos+KVdGMg
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAj4H+B4ACgkQO8l8XBKTpRQ+6gCdENZ5cXOcdLimjQHE3+PrYX3X
j1QAn33J0LOZUzFA15E+uPrAiDlU9gTB
=e2yO
-----END PGP SIGNATURE-----

--gKMricLos+KVdGMg--