help for using msvcrt.kbhit() with Python 2.3 editors?

dbrown2 at yahoo.com dbrown2 at yahoo.com
Thu Aug 14 16:17:57 EDT 2003


Mark,

Thanks for the repy.  In followup I see that msvcrt is a dll and reads
as "microsoft visual C++ run time" or something along those lines.  I
guess msvcrt is assuming a standard console and is somehow generating
the keypress events in a stream format then?  That's important to know
and probably belongs in the python msvcrt module documentation for us
less-sophoisticated users.  I notice now it says "console I/O" in the
module but I didn't distinguish between a console running python and
the interactive enviroment inside the editors until now.  I'm still
confused as to what happens when there is no console present and you
call msvcrt.kbit().  Shouldn't it produce a script runtime error?

Clearly my code couldn't have worked before in Python 2.2. I can't
even imagine how I could have written it originally without noticing
the problem.

This kind of enviroment-related issue has hit me before unfortunately.
 So I take it there is no cross-platform or standard way to detect a
key press. How do people deal with running a simple script until the
user interupts it.  That's all I need.  I think PythonWin has a
right-click feature on its 'process' icon to stop running scripts but
it would be nice to have the script be aware of the user input and
close down the same way everywhere and a little more gracefully.  I
suppose I could look for a KeyboardInterrupt error.  Is that the error
I should see when a running script is aborted by the user?


Mark Hammond <mhammond at skippinet.com.au> wrote in message news:<bheg3q$2gvi$2 at arachne.labyrinth.net.au>...
...
> 
> This will not work for Windows programs.  Keystrokes are delivered to 
> GUI programs via windows messages, not via stream type functions.  Thus, 
> having a GUI program with no existing message loop detecting key presses 
> is quite difficult.
> 
> Mark.




More information about the Python-list mailing list