msvcrt.getch() overly receptive in idle?
Frank Miles
fpm at u.washington.edu
Tue Jun 12 23:41:15 EDT 2001
In article <u4rtl46mf.fsf at ctwd0143.fitlinxx.com>,
David Bolen <db3l at fitlinxx.com> wrote:
>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.
Thanks. This makes sense. This indirect approach will hopefully
provide a way to debug apps that need this kind of functionality.
-frank
--
More information about the Python-list
mailing list