how to stop a loop with ESC key? [newbie]

Fredrik Lundh fredrik at pythonware.com
Tue Nov 8 02:59:17 EST 2005


"mo" <WYWAL_TOmich202 at o2.pl> wrote:
> Can somebody explain how to stop a WHILE loop in running program by pressing
> ESC key?

depends on the platform.

on windows, you can use the mscvrt module:

    import msvcrt

    while ...:
        ...
        if msvcrt.kbhit() and msvcrt.getch() == chr(27):
            break
        ...

also see the second example on this page:

    http://effbot.org/tag/python.msvcrt

</F>






More information about the Python-list mailing list