AutoHotkey Community

It is currently May 26th, 2012, 8:11 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: July 16th, 2009, 5:30 am 
Offline

Joined: July 16th, 2009, 5:23 am
Posts: 2
I've this AHK script that works and does what I need it to do However, there's some stuttering in application when it's running.
Here's what it does: it check a small area (25x25px) of the screen and does ImageSearch loop comparing that area to one of the several icons.
When it finds a match, it enters another smaller loop in which it repeatedly sends a keystroke for that action and checks if this one icon remained on the screen.
Like I said - it is functional, but perhaps great collective will have some advise on optimising it a bit? Thanks!

Code:
#MaxThreadsPerHotkey 3
CapsLock::
#MaxThreadsPerHotkey 1
if RotationLoop
{
    RotationLoop := false
    return
}
RotationLoop := true
Loop
{

found :=
lastfound := 0
Loop, 7

   {
      ImageSearch, OutputVarX, OutputVarY, 772, 445, 798, 471, *64 Action_Icon%A_Index%.bmp
      if Errorlevel = 0
      {
         found := A_Index
         If found !=
         {
              Loop
            {
            Send %found%
            sleep 50
            ImageSearch, OutputVarX, OutputVarY, 772, 445, 798, 471, *64 Action_Icon%found%.bmp
            if Errorlevel != 0
               break
            }
            
            break
         }
      }
   }

    sleep 250
    if not RotationLoop
        break
}
RotationLoop := false
return



Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 16th, 2009, 8:41 am 
--> SetTimer


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 16th, 2009, 8:05 pm 
Offline

Joined: July 16th, 2009, 5:23 am
Posts: 2
RTFM. wrote:
--> SetTimer


I'm sorry, I don't see how the use of SetTimer might be of help here. Application is putting a fairly heavy load on CPU (75-80%) continuously and per docs:
Quote:
A timer might not be able to run as often as specified under the following conditions:

1. Other applications are putting a heavy load on the CPU.
2. The timer subroutine itself takes longer than its own period to run, or there are too many other competing timers (altering SetBatchLines may help).


Am I missing something? I did add a second, smaller loop that fires when one of the icons is identified. This smaller loop sends keystroke repeatedly and does ImageSearch just for that icon to see if the action took place.
That helped with performance a bit but I'm sure there's more that can be done. I'll post code shortly.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 17th, 2009, 9:26 am 
Offline

Joined: February 11th, 2005, 6:31 am
Posts: 174
Location: Germany
to reduce the heavy CPU load, you may insert a sleep command in every loop... perhaps sleep 200 :?:


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: [VxE], Bing [Bot], BrandonHotkey, Google Feedfetcher, over21, SifJar, StepO and 69 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