I think you don't need such a long delay to reduce the cpu usage to 10%. How much does the CPU use when your app is not running?
I'd suggest to use a loop that will check for mouseposition
every 5 or so millisecs. This will let windows use most of the cpu time, but limit the lag with your hover effect.
Make sure not to update graphics and Flip etc. when there's no need for it.
You can make a test:
as you can see, checking the mouseposition 1000 times takes about 1 or two millisecs() on eg. a 1.6 GHz puter. So if you check it only once every 5 Millisecs, your app really won't eat a lot of CPU power. But as I said, make sure not to use any graphics update as long as there's no user action.
you may use a variable that indicates if the user is active. something like
So in this example, after about 5 seconds of inactivity, the graphics won't be updated anymore until the mouse is moved again.
I'd suggest to use a loop that will check for mouseposition
every 5 or so millisecs. This will let windows use most of the cpu time, but limit the lag with your hover effect.
Make sure not to update graphics and Flip etc. when there's no need for it.
You can make a test:
tt=millisecs() for i=0 to 1000 if mousex() > 100 and mousex()<200 if mousey()>200 and mousey()<300 ; endif endif next tt2=millisecs() print tt2-tt waitkey()
as you can see, checking the mouseposition 1000 times takes about 1 or two millisecs() on eg. a 1.6 GHz puter. So if you check it only once every 5 Millisecs, your app really won't eat a lot of CPU power. But as I said, make sure not to use any graphics update as long as there's no user action.
you may use a variable that indicates if the user is active. something like
active=0 while keydown(1)=0 mx=mousex() my=mousey() if (mx<>old_mx) or (my<>old_my) old_mx=mx old_my=my active =300 endif if active>0 then active=active-1 cls if my>buty1(0) and my<buty2(0) and mx>butx1(0) and mx<butx2(0) butimg(0)=butimg_hi(0) else butimg(0)=butimg_lo(0) endif drawimage butx1(0),buty1(0),butimg(0) flip else delay 5 ; active is zero, slumber mode endif wend
So in this example, after about 5 seconds of inactivity, the graphics won't be updated anymore until the mouse is moved again.