Jump to content

Autoit Script Problem Unique To Certain Pcs


Recommended Posts

I've written an AutoIt Ver3 script that gets an area of the screen using PixelGetColor with nested For...next loop and stores it into string1. I then compare string1 to string2. String2 is basically a snaphot of the screen I am looking for. I've made sure to zeroize string1 between each iteration. This works great on my PC and some others. However, some users complain that after the first iteration the script slows to a crawl taking extraordinarily long to do the comparisons. I am using the latest version of AutoIt Ver3. Each string is approximately 1k in length. Any ideas?

Adding the following in case you all need more info:

Here is the basic code:

Dim $color

Dim $readout

Dim $found

Dim $good

Dim $check

Dim $resource

$found = 0

$check = 0

$resource="987325981625906129086590265908265902867977528753682769827609732675672567256786725867267925862-56798671893671907836470"

$readout = ""

Main Routine....

Func CheckResource()

for $y = 62 to 70

for $x = 109 to 115

$color = PixelGetColor($x, $y)

$readout = $readout & $color

next

next

for $check = 1 to StringLen($resource)

if StringMid($resource,$check,1) = StringMid($readout,$check,1)then

$good = $good + 1

endif

Next

if $good > (StringLen($resource) - $tolerance) then

$readout = ""

$good = 0

$found = 1

else

$good = 0

$readout = ""

endif

EndFunc

The above is the code I use to check an area of screen against a known quantity and is where users complain that the system slows down after the first run through. I am using an AMD Athlon 2.6g processor with 1G memory Win XP Pro and this is running without a hitch. Another user is using a P4 3g Laptop with WinXP. These two system however are having problems;

AMD 1.9g 512k ram Win2K

AMD Athlon 2800 1g ram WinXP

Any ideas? TIA

Edited by dmbech
Link to comment
Share on other sites

I am not sure why you have so many variables, but this modified version of yours runs pretty fast and didn't seem to change from machine to machine.

I will run a few more tests, but why do you use stringmid when you seem to know the whole string?

well would this work for ya?

I had to change the resourse to match my data, but you can uncomment the clipget() to get yours with one run of it.

Dim $color
Dim $readout
Dim $found
Dim $good
Dim $check
Dim $resource

$found = 0
$check = 0
;$resource="987325981625906129086590265908265902867977528753682769827609732675672567256786725867267925862-56798671893671907836470"
$resource="998144099814409981440998144099814409981440998144099814409981440998144099814409981440998144099814

4099814409981440998144099814409981440998144099814409981440998144099814409981440998144099814409981440

9981440998144099814409981440998144099814409981440998144099814409981440998144099814409981440998144099

8144099814409981440998144099814409981440998144099814409981440998144099814409981440998144099814409981

440998144099814409981440998144099814409981440"
$readout = ""

;Main Routine....
For $test=1 To 1000
CheckResource()
Next

Func CheckResource()
$readout=""
for $y = 62 to 70
     for $x = 109 to 115
          $readout = $readout & PixelGetColor($x, $y)
     next
next
;  clipput($readout); used this to grab my string colors

If $readout=$resource Then 
    Tooltip("Matched Known Data"& $test,0,0)
Else
    Tooltip("Did not match known data"& $test,0,0)
EndIf
EndFunc

AutoIt3, the MACGYVER Pocket Knife for computers.

Link to comment
Share on other sites

Thanks for the reply. I decided to use the midstring to evaluate the variable character by character. Reasoning is that due to slight screen variations the captured screen pixles will not always EXACTLY match the known string. There will be slight variations, hence the

if $good > (StringLen($resource) - $tolerance) then

Which after the character by character comparison evaluates the results and determines if the screen area matches the known string within a certain tolerance.

Can you think of another way to do this? Thanks again.

Link to comment
Share on other sites

I actually did print that thread out this morning. However, I don't see a whole lot of difference. Rather than using string that thread is using arrays for storage of the pixel data. There is still a need to do some kind of comparison and rather than a char by char sting comparison you would be doing an array comparison. Faster? More reliable? Seems either should do the trick.

Link to comment
Share on other sites

Since I placed the entire string into memory (all the BGR values,) and that is my $resource, you can do the = comparision to that like I did.

if you have one single pixel off, you will get the error.

Due to screen variations, the RGB or BGR values will be off on every pixel I imagine, but you can do a pixel by pixel search. or an array search like this code replacement:

Dim $color
Dim $readout
Dim $found
Dim $good
Dim $check
Dim $resource

$found = 0
$check = 0
$resource=StringSplit(":9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440:9981440",":")
$readout = ""

;Main Routine....
For $test=1 To 1000
CheckResource()
Next

Func CheckResource()
$readout=""
for $y = 62 to 70
     for $x = 109 to 115
          $readout = $readout &":"& PixelGetColor($x, $y)
     next
next
 clipput($readout); used this to grab my string colors
$color=StringSplit($readout,":")
For $i=1 To $resource[0]
 If $color[$i]<>$resource[$i] Then $found=$found+1
Next
Tooltip($found&"Errors found --- test#"&$test,0,0)
$count=0
$found=0
EndFunc

but you can do an individual test if you like, I am not sure how gamma and all those setting will effect the pixels, but I imagine that you might be able to set up some comparision with a known screen value, say a pixel in splash screen.

AutoIt3, the MACGYVER Pocket Knife for computers.

Link to comment
Share on other sites

This gave me a good idea for a UDF,

Screen gamma value, or color variation.

display up a splashscreen, then pixel search it, and compare the hex values of each RGB, to known RGB, and there is your exact variation. (in theory)

AutoIt3, the MACGYVER Pocket Knife for computers.

Link to comment
Share on other sites

exactly dmbech. You could then theoretically have an exact pixel match. I think I will use a SplashTextOn first and then SplashImageOn for my test subject, so I can choose the color.

Lucky AutoIt is not as colorblind as I am. :whistle:

my quick color test:

SplashTextOn("screentest", "", -1, -1, 0, 0, 1, "", 24)
$colorcorection="D8E9EC"
$var = Hex(PixelGetColor(10, 100), 6)
SplashOff()
MsgBox(1,$colorcorection,$var)
Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Link to comment
Share on other sites

Quick dirty test.

Dim $color
Dim $readout
Dim $found
Dim $good
Dim $check
Dim $resource

$found = 0
$check = 0
$resource=StringSplit(":984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00:984E00",":")
$readout = ""
$Variance=colorcheck()

;Main Routine....
For $test=1 To 1000
CheckResource()
Next

Func CheckResource()
$readout=""
for $y = 62 to 70
    for $x = 109 to 115
         $readout = $readout &":"& Hex(PixelGetColor($x, $y), 6) 
    next
next
;clipput($readout); used this to grab my string colors
$color=StringSplit($readout,":")
For $i=1 To $resource[0]
If (dec($color[$i])-$Variance)<>dec($resource[$i]) Then $found=$found+1
Next
Tooltip($found&"Errors found --- test#"&$test,0,0)
$count=0
$found=0
EndFunc


Func colorcheck()
    SplashTextOn("screentest", "", -1, -1, 0, 0, 1, "", 24)
$colorcorection="D8E9EC"
$var = Hex(PixelGetColor(10, 100), 6)
SplashOff()
Return dec($colorcorection)-dec($var)
EndFunc

Note, I use the default splashscreen color.

color correction seems to work, here is a quick version:

SplashTextOn("screentest", "", -1, -1, 0, 0, 1, "", 24)
$colorcorection="D8E9EC"
$var = Hex(PixelGetColor(10, 100), 6)
SplashOff()
MsgBox(1,$colorcorection,$var)
$variance=colorcheck()
MsgBox(1,dec($var),dec($colorcorection)-$variance)

Func colorcheck()
    SplashTextOn("screentest", "", -1, -1, 0, 0, 1, "", 24)
$colorcorection="D8E9EC"
$var = Hex(PixelGetColor(10, 100), 6)
SplashOff()
Return dec($colorcorection)-dec($var)
EndFunc

AutoIt3, the MACGYVER Pocket Knife for computers.

Link to comment
Share on other sites

scriptkitty - looks cool will see about implementing something like this with mine. I found the issue with the users and my script it seems to be a resource issue. The client software being used is a really memory hog and wants all the windows resources for itself and therefore causes the script to run slower on less powerful PCs. However, if you start the script as follows:

start /realtime path:scriptname

Everything works fine! Is there a way to do this from within the script? Like tell windows to allocate it the same resources as everything else?

Link to comment
Share on other sites

scriptkitty -  looks cool will see about implementing something like this with mine.  I found the issue with the users and my script it seems to be a resource issue.  The client software being used is a really memory hog and wants all the windows resources for itself and therefore causes the script to run slower on less powerful PCs.  However, if you start the script  as follows:

start /realtime path:scriptname

Everything works fine!  Is there a way to do this from within the script?  Like tell windows to allocate it the same resources as everything else?

At some point I hope to get a ProcessSetPriority function integrated into AutoIt which would allow you to change the priority of any process on the system (including your script). I have it written, but haven't submitted it yet since Jon isn't making any changes to AutoIt at the moment.
Link to comment
Share on other sites

I am not sure why you have so many variables, but this modified version of yours runs pretty fast and didn't seem to change from machine to machine.

Hi

Is your machine a W98. See my new post W2K PIV execution is slower then W98 on a Celeron500.

Edited by venussoftop

RegardsBhavbhuti

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...