msvcrt.getch() overly receptive in idle?

David Bolen db3l at fitlinxx.com
Tue Jun 12 19:32:08 EDT 2001


fpm at u.washington.edu (Frank Miles) writes:

> I'm trying to get getch() working in Windows (Python 2.0).  It seems to
> work fine outside of Idle, but inside Idle it immediately returns a
> character with the value 255.
> 
> Can anyone point me to the obvious solution?  Thanks!

I expect that getch() requires a working "console" window, and when
you run Idle you don't get one as its set to use pythonw.exe.  Thus,
it's technically not able to process any keystrokes and returns
immediately.

You could try to verify that by starting Idle from the command line
with the standard python.  (But you may have to be in that console
window to trigger the getch() to return).

A GUI doesn't really have individual keystrokes sent as console
characters, but instead receives events upon keypresses.  So a getch()
call in a GUI application is sort of non-sensical (within the GUI
framework).

To do the equivalent in a GUI, you'd need to wait for a keypress
event.  I'm not sure how easy or not it would be to tie into Idle's
event loop to notice such a thing.

--
-- David
-- 
/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: db3l at fitlinxx.com  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/



More information about the Python-list mailing list