[Tutor] loop until a keypress

Christian Witts cwitts at compuscan.co.za
Mon Jan 30 09:49:48 CET 2012

On 2012/01/30 07:20 AM, Surya K wrote:
> 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 msvcrt
> chr = 0
> while 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 working
> Can 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,
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
There isn't a platform independent module for capturing keystrokes 
unfortunately.  You can take a look at this StackOverflow answer though 
which could help you out 


Christian Witts
Python Developer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120130/2ecca6f0/attachment.html>

More information about the Tutor mailing list