AutoHotkey Community

It is currently May 26th, 2012, 4:57 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: February 19th, 2009, 1:33 am 
Offline

Joined: January 8th, 2009, 11:36 pm
Posts: 42
I feel uneasy about using too many timers at the same time.
Do timers slow down the CPU performance?

Eg. If i set a timer for a very short interval (eg 1 ms), it means the computer is checking every millisecond for something.

Will this affect the responsiveness of key presses?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 19th, 2009, 2:38 am 
depends, post your code


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 19th, 2009, 6:46 am 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
AHK Help File wrote:
Currently, timers cannot run much more often than every 10ms on Windows XP/2000/NT and about 55ms on Windows 9x. Specifying a Period less than this will usually result in an actual interval of 10 or 55...

The easiest way to find out if your script will slow down your PC is to try it and find out. If you explain what you're trying to do, someone may have a better way to code it than multiple timers as well.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 19th, 2009, 5:52 pm 
Offline

Joined: January 8th, 2009, 11:36 pm
Posts: 42
jaco0646 wrote:
AHK Help File wrote:
Currently, timers cannot run much more often than every 10ms on Windows XP/2000/NT and about 55ms on Windows 9x. Specifying a Period less than this will usually result in an actual interval of 10 or 55...

The easiest way to find out if your script will slow down your PC is to try it and find out. If you explain what you're trying to do, someone may have a better way to code it than multiple timers as well.



Well, the whole program is about 5000 lines now!, but I have included all the code that involves timers...

Code:
settimer,checktimeidle,%idleinterval%
settimer,wm_testactive,200


~rbutton::
if 3menuflag
{
   playit(menuout)
   3menuflag:=false
}
else
{
   if 2menuflag
   {
      playit(menuout)
      2menuflag:=false
            sendplay {home}{del 70}
   }
   else
   {
   if 1menuflag
   {
      playit(menuout)
      playvar:="menuout"
      settimer,playsound,-400             ;plays sound again, the timer allows me to continue without
      1menuflag:=false                     ;having to wait for sound
      }
      
   }
}
suspend,off
return



WM_MOUSEMOVE()
{
     static CurrControl, PrevControl, _TT  ; _TT is kept blank for use by the ToolTip command below.
     global logo,alertcolor,info,txtfont
    CurrControl := A_GuiControl
    ;msgbox,,, %A_Guicontrol%.%currControl%.%prevcontrol%,1
    If (CurrControl <> PrevControl and not InStr(CurrControl, " "))
    {
       SetTimer, DisplayToolTip,%tooltiptimerdelay%
       PrevControl := CurrControl
    }
    return
    DisplayToolTip:
    ;msgbox,,, %currcontrol%.%currcontrol_TT%,1
    SetTimer, DisplayToolTip, Off
    curr_TT:=CurrControl . "_TT"
    if (%curr_TT%<>"")
    {
         infobox1(0,%Curr_TT%,logo,20,10,15,20,alertcolor,info,txtfont,txtfontstyle)
      }
    return
}


functionkey(key ="zzz")                   ;this function uses a weapon
{
   global  ;lowgravexpired,globallowgwith
   gui,1:submit,nohide
   if (key="zzz")
      stringtrimleft,hkey,A_thishotkey,1
   else
      hkey:=key
      
   lowg:=hkey . "Lowgravity"
   lowgval:=%lowg%
   ;msgbox %changestrength%::%hkey%::%changestrengthval%%changestrengthvalvar%
   
      if ((globallowg=1 or lowgval=1)and lowgravexpired=true)
   {
      playit(startup)
      if globallowgwith
         lowgrav(1,1)
      else
         lowgrav(1,0)
      lowgravexpired:=false       
      ;A FLAG TO SHOW LOW GRAV IS USED - A timer is then set, and lg will not be used til the timer runs out when
      ;  the FLAG is reset back to 1, once set , low gravity remains for the users turn
      settimer,restorelg,-%lowguseddelay% ; negative value makes it only run once Default value for lowguseddelay is 30 secs (30000)
   }
   ;hotkey, %fkey%,off, UseErrorLevel
   presskey(hkey)
   if globalsetstrength
      presskeyd(globalstrengthval)
   
   return
}   

restorelg:
      lowgravexpired:=true
return



~mbutton::
   suspend,on
   ;msgbox ,,,2menuflag:%2menuflag%,1
   if 2menuflag
   {
      if !3menuflag
      {
         playit(menuin)
         3menuflag:=true
      }
   }
   else
   {
      if 1menuflag
      {
         playit(menuin)
         2menuflag:=true
      }
      else
      {
         keywait,mbutton,T0.3          ;u held middle button down for 0.3 secs or more
         ;msgbox kw:%errorlevel%
         if (errorlevel =1)
         {
            1menuflag:=true                ;activates the mouse menu so u can scroll 1st menu
            playit(menuin)
            playvar:="menuin"
            settimer,playsound,-800          ;timer allows me to continue without havinng to wait for
         }                                   ;sound
         else
         {
               playit(menuout)
               }
      }
   }   
   suspend off
return
playsound:
   playit(%playvar%)
   playvar:=""
return



setwormfriend:                           ;This is a 'gimmicky' thing that displays a worm on screen
gui 1:submit,nohide                     ;He will do different random actions at different delays
tempcolor = d2a6ff                      ; At the moment he only does 2 different actions
wormpic1:=picdir . "worm1.png"           
   wormpic2:=picdir . "worm2.png"
   wormpic3:=picdir . "worm3.png"
   wormpic4:=picdir . "worm1o.png"
   wormpic5:=picdir . "worm2o.png"
   wormpic6:=picdir . "worm3o.png"
   squeal1:=defsoundir . "squeak1"
   squeal2:=defsoundir . "squeak2"
   squeal3:=defsoundir . "squeak3"
   squeal4:=defsoundir . "squeak4"
   squeal5:=defsoundir . "squeak5"
if wormfriend
{
   xpos:=maxpixright-200
   ypos:=maxpixbottom-200
   direction:="left"
   gui, 20:+toolwindow +disabled +alwaysontop -sysmenu -caption +lastfound +noactivate
   gui, 20:color,%tempcolor%
   gui, 20:add,picture,vwormfriend h60 w-1,%wormpic4%
   WinSet, TransColor, %tempcolor%
   gui 20:show,w180 h180 x%xpos% y%ypos%,mywormfriend
   Gui,20:+LastFound
   GroupAdd, WAGui, % "ahk_id " . WinExist()
   settimer changewormfriend,% wormfrienddelay * 1000      ;timer to set the delay of worm doing actions
}
else
{
      gui 20:destroy
      settimer changewormfriend,off
}
return
   


changewormfriend:
   maxwormactions:=2
   random,randwormaction,1,maxwormactions
   direction:=wormaction%randwormaction%(direction)
return


wormaction1(direction ="left")
{
   global
   wingetpos,xpos,ypos,,,mywormfriend
   x:=0
   whichpic:=1
   random,moves,20,100
   loop %moves%
   {
      if ((xpos-x)<=0)
         direction:="right"
      else if ((xpos+x)>=maxpixright)
         direction:="left"
      pic1:=direction="left" ? "wormpic4" : "wormpic1"
      pic2:=direction="left" ? "wormpic5" : "wormpic2"
      pic3:=direction="left" ? "wormpic6" : "wormpic3"
      inpic1:=%pic1%
      inpic2:=%pic2%
      inpic3:=%pic3%
      if (whichpic=1)
      {
         winmove,mywormfriend,,xpos-x,ypos +2
         guicontrol, 20:,wormfriend,*h60 %inpic1%
         playit(squeal1)
         }
      else if (whichpic=2)
      {
         winmove,mywormfriend,,xpos-x,ypos
         guicontrol, 20:,wormfriend,*h60 %inpic2%
         }
      else if (whichpic=3)
      {
         winmove,mywormfriend,,xpos-x,ypos -2
         guicontrol, 20:,wormfriend,*h60 %inpic3%
         playit(squeal2)
         whichpic:=0
         }
         
      if (direction="left")
         x+=5
      else
         x-=5
      sleep 30
      whichpic++
   }
return direction
}
wormaction2(direction ="left")
{
   global
   wingetpos,xpos,ypos,,,mywormfriend
   x:=0
   whichpic:=1
   random,moves,20,100
   loop %moves%
   {
      if ((xpos-x)<=0)
         direction:="right"
      else if ((xpos+x)>=maxpixright)
         direction:="left"
      pic1:=direction="left" ? "wormpic1" : "wormpic4"
      pic2:=direction="left" ? "wormpic2" : "wormpic5"
      pic3:=direction="left" ? "wormpic3" : "wormpic6"
      inpic1:=%pic1%
      inpic2:=%pic2%
      inpic3:=%pic3%
      if (whichpic=1)
      {
         winmove,mywormfriend,,xpos-x,ypos +2
         guicontrol, 20:,wormfriend,*h60 %inpic1%
         playit(squeal1)
         }
      else if (whichpic=2)
      {
         winmove,mywormfriend,,xpos-x,ypos
         guicontrol, 20:,wormfriend,*h60 %inpic2%
         }
      else if (whichpic=3)
      {
         winmove,mywormfriend,,xpos-x,ypos -2
         guicontrol, 20:,wormfriend,*h60 %inpic3%
         playit(squeal2)
         whichpic:=0
         }
         
      if (direction="left")
         x+=5
      else
         x-=5
      sleep 30
      whichpic++
   }
return direction
}



autodropfunction:
     ;msgbox autodrop is : %autodrop% 
   if autodrop
   {
      
       actualautodropdelay:=autodropdelay * 1000
       if !recurringautodrop
      {
         actualautodropdelay:=0-actualautodropdelay
         
      }
      playit(startup)
      settimer,dropit,%actualautodropdelay%
   }
return

autodropset:
   if chklongkeypress("d",error)
   {
      recurringautodrop:=recurringautodrop=true ? false : true
      recurrstring:=recurringautodrop=true ? "Recurring" : "Once Only"
      suspend on
      sendplay {home}{del 10}
      sendinput %recurrstring%
      suspend off
   }
   else
   {
      if (a_priorhotkey="")
         return
      if autodrop
      {
         if (a_thishotkey=a_priorhotkey and a_timesincepriorhotkey<1000)
         {
            playit(error)
            settimer,dropit,off
         }
            else
         {   
            gosub,autodropfunction
         }
      }
   }
   
return

dropit:
   gui,1:submit,nohide
   playit(hysteriaweaponsoff)
   functionkey(autodropfunctionkey)
   presskey("Enter")
return


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, Google [Bot], poserpro, SifJar, SKAN and 41 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group