Jump to content
rimmi2002

Is there a way to run this code faster on Windows 10?

Recommended Posts

rimmi2002

Hi I have an automation program for work which detects pixels to do certain actions that are controlled by voice command. This script worked at a very fast speed on Windows 7. However with Windows 10 pixelsearch() has been crippled. Therefore the script is running extremely slow. I was wondering if there's any other way to accomplish what I have done with my script below that can run faster on Windows 10.

The script has one main function called findword(). It takes an array of pixels and finds the matching spot on the screen. If the spot is found it sets global variables $gwx and $gwy to the location of that spot and returns true. If nothing is found it returns false.

 

Global $gX = 0, $gY = 0, $gWx = 0, $gWy = 0

Global $SampleArray[15] = [298, 303, 0x6c6c6c, 10, 0x6c6c6c, 16, 0xA1A1A1, 32, 0xA1A1A1, 41, 0x4F4F4F, 50, 0x959595, 76, 0xA1A1A1] 

Func findword($SA, $Word) ;$SA is search area, $word is array [dummy,dummy,1st color, 2nd pixel ofset, 2nd pixel Color, 3rd pixel ofset, 3rd pixel Color......so on]

    If Not IsArray($Word) Then Return False

    If IsArray($Word[0]) Then
        For $a In $Word
            If findword($SA, $a) Then Return True
        Next
    ElseIf IsArray($Word) Then

        If Not IsArray($SA) Then
            $SA = SetupSA($Word)
        EndIf

        $l = UBound($Word) - 1
        $limit = $Word[$l - 1]
        If pcheck($SA[0], $SA[1], $SA[2], $SA[3], $Word[2]) Then
            $x1 = $gx
            $y1 = $gy
            If serialpcheck($x1, $y1, $Word) Then

                $gWx = $x1
                $gWy = $y1
                $wordfound = True
                Return $wordfound
            EndIf
            If $x1 = $SA[2] And $y1 < $SA[3] Then
                $SA[1] = $y1 + 1
                Return findword($SA, $Word)
            ElseIf $x1 = $SA[2] And $y1 > $SA[3] Then
                $SA[1] = $y1 - 1
                Return findword($SA, $Word)
            ElseIf $x1 < $SA[2] And $y1 < $SA[3] Then
                Local $temp[4] = [($x1 + 1), $y1, $SA[2], $y1]
                If Not findword($temp, $Word) Then
                    $SA[1] = $y1 + 1
                    Return findword($SA, $Word)
                Else
                    Return True
                EndIf

            ElseIf $x1 < $SA[2] And $y1 > $SA[3] Then
                Local $temp[4] = [($x1 + 1), $y1, $SA[2], $y1]
                If Not findword($temp, $Word) Then
                    $SA[1] = $y1 - 1
                    Return findword($SA, $Word)
                Else
                    Return True
                EndIf
            ElseIf $x1 < ($SA[2] - $limit) And $SA[1] = $SA[3] Then
                $SA[0] = $x1 + 1
                Return findword($SA, $Word)
            EndIf
            Return False
        EndIf
    EndIf

    Return False
EndFunc   ;==>findword

Func serialpcheck($x1, $y1, $Word) ;used by Findwordchecks multiple pixels from array of offsets and pixel. Return True if all match
    $l = UBound($Word)
    $imax = ($l - 3) / 2
    $go = True
    $count = 3
    $i = 0
    While $i < $imax And $go
        If Not pcheck($x1 + $Word[$count], $y1, $x1 + $Word[$count], $y1, $Word[$count + 1]) Then
            $go = False
        EndIf
        $i += 1
        $count += 2
    WEnd
    Return $go

EndFunc   ;==>serialpcheck


Func pcheck($x1, $y1, $x2, $y2, $pixel, $var = 0, $click = False, $stop = False, $msg = 'Pcheck Failed')

    If IsArray($pixel) Then
        $l = UBound($pixel)
        $n = 0
        While $n < $l
            If pcheck($x1, $y1, $x2, $y2, $pixel[$n]) Then
                Return True
            EndIf
            $n += 1
        WEnd
        Return False
    EndIf


    $pixel1 = PixelSearch($x1, $y1, $x2, $y2, $pixel, $var)
    If (@error) Then
        If $stop Then
            Pause($msg)
        EndIf
        Return False
    Else
        $gx = $pixel1[0]
        $gy = $pixel1[1]
        If $click Then MCLPixel()
        Return True
    EndIf
EndFunc   ;==>pcheck

 

Edited by rimmi2002

Share this post


Link to post
Share on other sites
AndyG

Hi!

9 hours ago, rimmi2002 said:

This script worked at a very fast speed on Windows 7.

..on YOUR Machine and YOUR settings of YOUR System!

9 hours ago, rimmi2002 said:

However with Windows 10 pixelsearch() has been crippled.

Definitely not!

9 hours ago, rimmi2002 said:

 Therefore the script is running extremely slow.

Interesting conclusion/inference...

9 hours ago, rimmi2002 said:

I was wondering if there's any other way to accomplish what I have done with my script below that can run faster on Windows 10.

You have nothing to do with your script, do changes to/with your system! 

Try to switch off AERO and/or other WIN10 "Visual effects" , which are (most in these cases) the reason of the "unexpected sudden slowishness" of  such amateurish code. 

 

Imho the better question would have been "How to ´do certain actions that are controlled by voice command´  without the use of PixelSearch?"

Share this post


Link to post
Share on other sites
rimmi2002
12 hours ago, AndyG said:

Hi!

..on YOUR Machine and YOUR settings of YOUR System!

Definitely not!

Interesting conclusion/inference...

You have nothing to do with your script, do changes to/with your system! 

Try to switch off AERO and/or other WIN10 "Visual effects" , which are (most in these cases) the reason of the "unexpected sudden slowishness" of  such amateurish code. 

 

Imho the better question would have been "How to ´do certain actions that are controlled by voice command´  without the use of PixelSearch?"

My machine is a Intel 4700k with 12gbRam and Running on a SSD. I understand the code is amateur, but it is the best I can do and it works well for me given my limited background in programming. I'm doing this to help me out because I have bilateral wrist disease and need such assistance to do my work. 

pixel search does not work nearly as fast in Windows 10 as it did in Windows 7 as there is no way to completely turn off Aero completely like it could be done in Windows 7. This has been discussed in multiple threads here. No one has found a workaround so far. This particular thread is probably the most helpful.

 

if you know of a better way for me to use voice commands through programming that can recognize text on the screen that is running in a Citrix server, on which there are no control options, throgh au3info.exe, I would be really happy to know the alternative.

 

My current set up is that I have set up hotkeys in DragonDictate to certain voice commands. When those voice commands are dictated the hotkey is pressed and the associated script is run through auto it.

My total code is about 4 to 5000 lines that I have built over a year or two to help me out with all my work. The backbone of my code is being able to use pixel search. My work is slowly migrating to Windows 10, eventually I will have to as well and I'm trying to find a solution that works prior to that happening.

Share this post


Link to post
Share on other sites
Nine

@rimmi2002 I am still on Windows 7 and I won't budge from it until there is a solution.  I know what challenge you are facing.  PixelSearch might not be the best solution but sometimes it does the work with very little programming investment.  Now that being said, the only thing that I could suggest is that you make this thread a well documented (very detailed and factual) reference on all the attempts you have tried and didn't work.  If that doesn't give you the solution, as least it will help all the others that facing the same problem.  It would be very interesting if you could show your stats along with your attempts.  Good luck !

ps. have you tried to run it in 16bits colors ?

Share this post


Link to post
Share on other sites
badcoder123

I can safely say here pixelsearch on Windows 10 takes ~25ms and pixelgetcolor takes ~15ms and runs extremely efficient with areo on or off

Edited by badcoder123

Share this post


Link to post
Share on other sites
rimmi2002
52 minutes ago, badcoder123 said:

I can safely say here pixelsearch on Windows 10 takes ~25ms and pixelgetcolor takes ~15ms and runs extremely efficient with areo on or off

25ms puts it at approximately 40 repetitions per second. I'm getting similar numbers with my set up with about 30 repetitions per second. That is not bad. However on Windows 7 you can get up to 16,000 repetitions per second. My code relies heavily on pixel search and as a result with only 40 repetitions per second it's runs really slow. What would otherwise take less than a second takes 20 to 30 seconds. As you can tell 16,000 versus 40 is about 400 times faster.

 

 

 

2 hours ago, Nine said:

@rimmi2002 I am still on Windows 7 and I won't budge from it until there is a solution.  I know what challenge you are facing.  PixelSearch might not be the best solution but sometimes it does the work with very little programming investment.  Now that being said, the only thing that I could suggest is that you make this thread a well documented (very detailed and factual) reference on all the attempts you have tried and didn't work.  If that doesn't give you the solution, as least it will help all the others that facing the same problem.  It would be very interesting if you could show your stats along with your attempts.  Good luck !

ps. have you tried to run it in 16bits colors ?

So far I have tried turning off Aero transparency effects, turning off Aero peek, turning off Aero snap, turning off basically anything with the name Aero and it and none of it works.

I have tried 16-bit colors.

People here have mentioned that pixel search is amateur programming. What other options do I have, I am willing to learn other things as long as they get the job done well.

 

 

 

Edited by rimmi2002

Share this post


Link to post
Share on other sites
BrewManNH

Do you have a working script that can demonstrate what you're seeing? Something that anyone can run and check your results.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
AndyG
14 hours ago, rimmi2002 said:

The backbone of my code is being able to use pixel search.

I tested "native" AutoIt Pixelsearch() on my Win10-machine with a pixel in the lower right corner (Traymenu). The resolution of my monitor is  2560x1440. The time finding this pixel was between 50 and 70 milliseconds. 

I don´t know what should be wrong with that!

What do you expect?

10 years ago i have written a script to find and click "Buttons".

 PushThebutton.zip

First you should try the demo. It should find and klick the windows-Button in the left lower corner of the screen.

PushTheButton.au3 helps you to create the "Buttons" you are searching for.

The prospeed.dll is not necessary, you can delete it if you like. One of tose functions inside makes the script 100 times faster...

If i have some time, i will replace the "prospeed.dll-call" with some few lines Assemblercode. But this piece of code is  from 2008, and works...

 

 

 

Share this post


Link to post
Share on other sites
Nine

Made a little benchmark, so everyone can run it on their machine and share results.  If you intend to test it, please do not modify it so we can compare apples with apples.  I compiled it x86 and I get about 2,150 pixelsearches per second on  Win7 x64 aero off.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Change2CUI=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
While 1
  Local $i=0
  Local $so = TimerInit()
  While TimerDiff($so) <= 1000
    PixelSearch(0,10,0,20,0xBBBBBB)
    PixelSearch(100,10,200,20,0xBBBBBB)
    PixelSearch(200,300,300,400,0xBBBBBB)
    PixelSearch(300,500,500,700,0xBBBBBB)
    PixelSearch(400,400,800,800,0xBBBBBB)
    $i += 1
  Wend
  ConsoleWrite("Operations per second: " & $i*5 & @CRLF)
WEnd

 

Edited by Nine

Share this post


Link to post
Share on other sites
BrewManNH

Running it on Win10 I get 80.

Which still means it's checking every 12.5 ms. compared to every .02 ms in Win7, I can't imagine anything not being detected in such a small fraction of a second even on Win10. It sure has slowed down in Win10, but still doable.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
rimmi2002
4 hours ago, Nine said:

Made a little benchmark, so everyone can run it on their machine and share results.  If you intend to test it, please do not modify it so we can compare apples with apples.  I compiled it x86 and I get about 2,150 pixelsearches per second on  Win7 x64 aero off.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Change2CUI=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
While 1
  Local $i=0
  Local $so = TimerInit()
  While TimerDiff($so) <= 1000
    PixelSearch(0,10,0,20,0xBBBBBB)
    PixelSearch(100,10,200,20,0xBBBBBB)
    PixelSearch(200,300,300,400,0xBBBBBB)
    PixelSearch(300,500,500,700,0xBBBBBB)
    PixelSearch(400,400,800,800,0xBBBBBB)
    $i += 1
  Wend
  ConsoleWrite("Operations per second: " & $i*5 & @CRLF)
WEnd

 

Got ~60 on Windows 10 64 bit  4770K Processor

Got ~55 on Win 7 64 bit with Aero On, 4670K processor 

Got ~3400 on Windows 7 64-bit Aero off, 4670K processor

 

Edited by rimmi2002

Share this post


Link to post
Share on other sites
Nine

@rimmi2002 It is fine to show your stats, but really read my previous thread.  If you want to make a change you got to take leadership and not waiting for someone else to solve your problem.  I told you to bring detailed facts on your attempts. Not just say i tried "something" and it didnt work.  Teach ppl how you did attempt to solve your problem step by step. 

Share this post


Link to post
Share on other sites
BigDaddyO

@rimmi2002 This isn't on topic, buy why are you interacting through the citrix client?  if your citrix session has access to a network drive, setup an .ini on a network share and create an app on your main system that simply flips values in the .ini whenever you want to do something.  Then you have an app you launch within citrix that simply watches that .ini for changes.

I'm forced to use Citrix a lot and I started with an .ini and have since moved to an sql database where all my flags are set and returned values are stored.  works pretty sweet.  In the morning, I launch the citrix box as a Window, launch a .bat file on my desktop that copies required files to the local citrix box %temp% and executes from there and it then just sits and looks for commands.  I then minimize/not close that window so there is an active desktop.  "you will need to use a winapi call to not let the citrix box sleep though"


hmm... I guess I have to have a signature...

Share this post


Link to post
Share on other sites
Juvigy

I got 50 with Aero and 2000 without on Win7 64Bit

 

Share this post


Link to post
Share on other sites
BrewManNH

 I'm still waiting to have someone tell me why they need to pixel check that many times a seconds. 12.5ms per check should be overkill for practically any need. Also "just because I want it faster" is not a valid reason. 

So what if it isn't as fast as in Win7, it is still more than fast enough unless you're doing something incredibly stupid in your code.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
Nine
1 hour ago, BrewManNH said:

 I'm still waiting to have someone tell me why they need to pixel check that many times a seconds. 12.5ms per check

Ok Brew, I will try to explain.  If you have to check a single area, I agree with you that 12.5 ms is good enough.  Now imagine a situation where you have to check a monitoring screen where there is about 60 small bars for specific colors. Black = Great, Green = Ok, Yellow = careful now, Red = problem.  Pixelsearch is an easy solution to just check all those without having to find WinCtrl for each of them.  In Win 7 it could take a fraction of a second to do it.  In win 10 it would take probably over 1 second to realize it.  One second where you cannot do anything else, is an enormous amount of time in computer time !

Share this post


Link to post
Share on other sites
Bilgus

why not copy the dc of the window and search that instead using a similar method or bitblit

Share this post


Link to post
Share on other sites
Nine
4 hours ago, Bilgus said:

why not copy the dc of the window and search that instead using a similar method or bitblit

I do not have any problem with this method, it is a very fast alternative.  But I was trying to help OP and I was curious to see the result...

Share this post


Link to post
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

×