[Tutor] keyboard interrupt
Marc Tompkins
marc.tompkins at gmail.com
Wed May 22 22:10:28 CEST 2013
On Wed, May 22, 2013 at 12:47 PM, Jim Mooney <cybervigilante at gmail.com>wrote:
> I made a simple ear frequency-tester, but I don't want it to go on
> forever, so I tried stopping it when I pressed a key, as below, but
> that doesn't work. I did check out keyboard interrupts but they seem
> unnecessarily complex just to stop a program. I'm not passing keys. Is
> there something simple I'm missing?
>
> import winsound
>
> try:
> for freq in range(100,32000,100):
> winsound.Beep(freq, 1000)
> except KeyboardInterrupt:
> pass
>
>
I've not used it myself, but I believe the KeyboadInterrupt is only
generated by one _specific_ keypress. You mentioned that you pressed a key
- did you try Control-C?
http://effbot.org/zone/stupid-exceptions-keyboardinterrupt.htm
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130522/ba4db613/attachment.html>
More information about the Tutor
mailing list