 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Queued_Up
Joined: 16 Jul 2009 Posts: 2
|
Posted: Thu Jul 16, 2009 4:30 am Post subject: Help with optimizing ImageSearch loop |
|
|
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
|
|
|
| Back to top |
|
 |
RTFM. Guest
|
Posted: Thu Jul 16, 2009 7:41 am Post subject: |
|
|
| --> SetTimer |
|
| Back to top |
|
 |
Queued_Up
Joined: 16 Jul 2009 Posts: 2
|
Posted: Thu Jul 16, 2009 7:05 pm Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
Andi
Joined: 11 Feb 2005 Posts: 173 Location: Germany
|
Posted: Fri Jul 17, 2009 8:26 am Post subject: |
|
|
to reduce the heavy CPU load, you may insert a sleep command in every loop... perhaps sleep 200  |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|