question about getch()

gliquidsnake at hotmail.com gliquidsnake at hotmail.com
Thu May 24 13:58:53 EDT 2007


Hey all,

I'm having a problem with using msvcrt.getch() .  What I want is some functionality like this:

print 'blah blah blah, good_input to do blah blah blah, exit_key to exit'

while input != exit_key:
    input = get_input_from_getch()

    if input == good_input:
        print input
        #do something
    if input == bad_input:
        #ask for new input
    if input == exit_key:
        pass

so, if the user's input is good, the input is printed to the screen and the user is allowed to put in more input.
if the user's input is bad, the input is not printed to the screen and python ignores the input.
if the user presses a designated key then the program continues.

for some reason, all I get when I try to implement getch() is python getting stuck in an infinite loop and printing "ÿ" continuously.  I tried using msvcrt.kbhit() to wait for a key to be pressed before continuing to getch() but it seems the program then skips the loop entirely.

I guess I just don't really understand how to use getch(). =(
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070524/cfac6c3c/attachment.html>


More information about the Python-list mailing list