This is an old copy of the Python FAQ. The information here may be outdated.

How do I check for a keypress without blocking?

Use the msvcrt module. This is a standard Windows-specific extension module. It defines a function msvcrt.kbhit which checks whether a keyboard hit is present, and msvcrt.getch which gets one character without echoing it.

import msvcrt

while 1:
    c = msvcrt.getch()
    print "Got character", repr(c)
    if c == "q":
        break # quit

CATEGORY: windows


A Django site. rendered by a django application. hosted by webfaction.