msvcrt.getch() and raw_input() get same key

Georg Simon georg.simon at bnmsp.de
Sun Oct 8 07:42:22 EDT 2000


Python 2.0b2 and Windows 98
----------------------------
import msvcrt
key = msvcrt.getch()
if key == '\000' :
    key = key+msvcrt.getch()
line = raw_input(': ')
print key, line
----------------------------
In this test script raw_input() is called after msvcrt.getch() .
In this case raw_input() receives as first character the same character
already received by by msvcrt.getch() :

Running the script in the DOS-box and pressing 'a' and 'Enter' 
gives the output 'a a'

The DOS-box then looks like this :

: a
a a
>>>

Is there a way to make msvcrt.getch() eat completely it's character ?

Thanks Georg




More information about the Python-list mailing list