Re: Is there a simple way to exit a while loop on keystroke?
- From: Miki <miki.tebeka@xxxxxxxxx>
- Date: Fri, 31 Aug 2007 17:33:43 -0000
Hello,
I am new to python, and have written a simple program to read a portYou might want to look at http://docs.python.org/lib/module-curses.html
via telnet. I would like it to run until any key is pressed. Of
course I wouldn't mind requiring a specific keystroke in the future,
but I would think this is simpler for now.
I have used kbhit() and getch() many times in C, but I can't find
anything similar in Python. I am using Linux also, so the msvcrt
code isn't an option. I have tried sys.stdin.read(), but that hangs
UNTIL a key is pressed.
Another solution is to ask the user to hit CTRL-C
from time import sleep
try:
while 1:
print "BEEP"
sleep(1)
except KeyboardInterrupt:
print "BYE BYE"
HTH,
--
Miki <miki.tebeka@xxxxxxxxx>
http://pythonwise.blogspot.com
.
- Follow-Ups:
- References:
- Prev by Date: Re: low level ethernet device access in linux
- Next by Date: troll vs. trawl [was: Re: list index()]
- Previous by thread: Is there a simple way to exit a while loop on keystroke?
- Next by thread: Re: Is there a simple way to exit a while loop on keystroke?
- Index(es):