[Tutor] How to use getch()?
Dick Moores
rdm at rcblue.com
Sun Aug 27 20:32:09 CEST 2006
At 10:55 AM 8/27/2006, Kent Johnson wrote:
>getch is a callable object (it implements __call__()) and is used like a
>function.
>
>If you only want to run on Windows, as your code suggests, just call
>msvcrt.getch() directly. This is a blocking call - it won't return until
>a key is pressed. If you don't want to block, use msvcrt.kbhit() to
>check whether a key is available before calling getch().
Thanks, Kent, but I'm afraid I don't know what a blocking call is.
Yes, I only want to run on Windows.
================
import msvcrt
c = 0
while True:
c += 1
(What goes here?) # Not 'if msvcrt.getch() == "k":', it seems.
break
print c
================
What I want to do is start the loop spinning, then hit "k" at some
point, and see what c is.
Dick
More information about the Tutor
mailing list