2008-07-15: Selected articles now have experimental "comment" links in the left column and at the bottom. You're welcome to use them for commenting and voting on articles. For a bit more on this, see this page. /F

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. this page was rendered by a django application in 0.02s 2008-07-25 10:12:07.513373. hosted by webfaction.