Read one key press.

Adrian Eyre a.eyre at optichrome.com
Mon Oct 18 12:58:12 EDT 1999


> key = raw_input("press a key: ")
> if key == 'a':
>     print "you pressed 'a'"
> elif key == '^['
>     print "you pressed escape"

This is a platform dependent issue.

For Win32, you can use:

import msvcrt
key = msvcrt.getch()

For unix, it's probably easiest to use the curses module:

import curses
win = curses.initscr()
key = win.getch()

I think then you're stuck with curses for all IO though.
Not sure about this one.

--------------------------------------------
Adrian Eyre <mailto:a.eyre at optichrome.com>
Optichrome Computer Solutions Ltd
Maybury Road, Woking, Surrey, GU21 5HX, UK
Tel: +44 1483 740 233  Fax: +44 1483 760 644
http://www.optichrome.com 
--------------------------------------------





More information about the Python-list mailing list