getch in python

Bengt Richter bokr at oz.net
Tue Sep 3 18:28:15 CEST 2002


On 3 Sep 2002 00:26:13 -0700, vvenka1 at hotmail.com (Venkat Venkataraju) wrote:

>Hi All
>
>Is there any function that behaves like getch() function in C? 
>
If you are on windows,

 >>> import msvcrt
 >>> while 1:
 ...     c=msvcrt.getch()
 ...     print '%02X: "%s"' % (ord(c),c)
 ...     if c=='q': break
 ...
 31: "1"
 32: "2"
 33: "3"
 61: "a"
 41: "A"
 40: "@"
 01: "?"
 71: "q"

(The 01 was a ctrl-A, and on a console window you see a happy face
instead of the question mark ;-)

For more info, see

    http://www.python.org/doc/current/lib/msvcrt-console.html

On *nix look into curses.

Regards,
Bengt Richter



More information about the Python-list mailing list