[Tutor] ReadKey function in Python

Michael P. Reilly arcege@shore.net
Thu, 6 Apr 2000 07:47:47 -0400 (EDT)


> 
> > On Wed, 5 Apr 2000 alan.gauld@bt.com wrote:
> > 
> > >I thought there might be a py-curses module but can't see 
> > one. (I usually
> > >use curses for this in C on Unix...)
> > 
> > "import curses" should do it:-) It's in the standard library.
> 
> Not for me its not... I tried Python 1.5.1 on Solaris 
> and 1.5.2 under NT and win95. They all give:
> 
> >>> import curses
> Traceback (innermost last):
>   File "<pyshell#0>", line 1, in ?
>     import curses
> ImportError: No module named curses
> >>> 
> 
> I did think a python curses would be kind of an obvious 
> thing to find, but I can't see it. Maybe I'm looking in 
> the wrong places?

The curses module is optional, like _locale, stdwin and various dbm
modules.  The creation of it must be activated in Modules/Setup of
the source distribution.  There are different curses packages that
could be compiled with the module, and not all platforms will have
curses available (OS/2, Mac, VMS).

Also, the original question was to get access to key-strokes (CntlLeft,
ShiftLck, etc.), not just input characters.  UNIX terminal device
drivers do not give access to such low-level values.  Curses is
designed and built on top of the terminal device driver; it's likely
that the WinXX port of (n)curses will not have that functionality as
well.

X-Windows and Windows will have access to those values, but in
different manners.  For example through Tkinter, this would be thru the
event system (the "keysym" attribute of the event object).  WxPython
and win32ui will likely have something similar.

  -Arcege

-- 
------------------------------------------------------------------------
| Michael P. Reilly, Release Engineer | Email: arcege@shore.net        |
| Salem, Mass. USA  01970             |                                |
------------------------------------------------------------------------