Alternative to raw_input ?

Peter Hansen peter at engcorp.com
Fri Feb 11 21:38:47 EST 2005


BOOGIEMAN wrote:
> On Fri, 11 Feb 2005 18:00:08 +0100, den wrote:
> 
> 
>>Did you try this:
>>
>>import msvcrt
>>msvcrt.getch()
> 
> 
> Yes, that's what I need. Thank you.
> BTW, sometimes program continues 
> without me pressing any button, why ? 

Probably because you had already hit a key earlier, and
it was still in the keyboard queue.

You can flush it first:

print prompt
while msvcrt.kbhit():
     msvcrt.getch()
msvcrt.getch()

Pack that up in a subroutine and call it when
you need to pause and continue only when the user
has seen your prompt.  Any previous keystrokes
will be discarded by the loop, then it will wait
for a new one to be hit.


-Peter



More information about the Python-list mailing list