[Tutor] loop until a keypress

Surya K suryak at live.com
Mon Jan 30 06:20:51 CET 2012


I want to run code until a "enter" is pressed. Well, it shouldn't wait for the user to enter "enter"
This is my code:
import msvcrtchr = 0while chr != 'q':     print "my code",     if msvcrt.kbhit():           chr = msvcrt.getch()
This isn't working the way I wanted. When ever I press enter, the loop is starting in a new line and continuing.
I even added "break" statement in "if" block but it isn't workingCan you tell me how to do that?
I am on windows. So, as msvcrt is for windows, I wonder if there is any module that works for both, 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120130/a5996b2a/attachment.html>


More information about the Tutor mailing list