On Tue, Jul 27, 2010 at 09:09, Alan Gauld <alan.ga...@btinternet.com> wrote:
> > "Richard D. Moores" <rdmoo...@gmail.com> wrote > > > Please see <http://tutoree7.pastebin.com/f3TaxDBc>. >> >> I'm trying to recall what I used to know, thus this simple script. But 'y' >> or 'q' do nothing. What's wrong? >> > > I don't think you need kbhit() I tried taking it out. You're right, Alan, I don't need it. See < http://tutoree7.pastebin.com/N8hdyqLZ> > or the sleep(.1) > Testing with and without sleep(.001) shows that sleep(.001) cuts the CPU usage dramatically, from ~50% to ~5%! The if kbhit test will only pass if the key is actually hit at that time. > Often it won't be so you will miss it. > I didn't see that, but with a bigger loop I may, I suppose. > I think getch() will wait for a key to be hit. > > But thats from memory and I'm too busy to try it out right now. > So I tried putting a counter, c, in the loop. See < http://tutoree7.pastebin.com/9Q8u3wLw>. It seems you're correct, in that if I hit 'y' 10 times and then 'q' to close, I'll get "c = 11". 5 'x's and 5 'y's and a 'q' also gets "c = 11", of course. Out of curiosity, I tried holding down 'z' (i.e., neither 'y' nor 'q' for exactly 10 seconds, and then hit 'q'. Got "c = 267". Thanks, Alan.
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor