Jump to content

Pixel Searcher not working


Recommended Posts

Ok my idea is to make a script that searches for 1 color in the screen and if it finds that color it will kill/close one process, the code I have made is below but for some reason its not working and When I run it, it immediatly closes

HotKeySet("{F9}", "StartScript")
$script = False

ToolTip("F9 = Start/Stop Script", 0, 0)


Func StartScript()
    If $script = False Then
        $script = True
    Else
        $script = False
        ToolTip("F9 = Start/Stop Script", 0, 0)
    EndIf
EndFunc   ;==>StartScript

While $script = True
    Dim $cordinates = PixelSearch(0, 0, @DesktopWidth, @DesktopHeight, 0xFFF200)
    If Not @error Then
        If ProcessExists("rPE.exe") Then
            ProcessClose("rPE.exe")
        EndIf
    EndIf
WEnd

If anyone could help me it would be great

Link to comment
Share on other sites

Hi and Welcome to the forums!

Did you really think that through? First you declare @script as False, and then you have a loop that asks it to be True. Thus the loop never runs, and what do you have after it? Nothing. So nothing happens (it exits).

I think what you want is closer to:

HotKeySet("{F9}", "StartScript")
$script = False

ToolTip("F9 = Start/Stop Script", 0, 0)
Sleep(2000)     ;So we have time to read it
ToolTip("")     ;Remove the ToolTip

While 1
    Sleep(10)       ;We don't want to use up the whole cpu do we?
    While $script = True
        Dim $cordinates = PixelSearch(0, 0, @DesktopWidth, @DesktopHeight, 0xFFF200)
        If Not @error Then
            If ProcessExists("rPE.exe") Then
                ProcessClose("rPE.exe")
            EndIf
        EndIf
    WEnd
WEnd

Func StartScript()      ;functions are normally placed last, make it easier to browse the code
    If $script = False Then
        $script = True
    Else
        $script = False
        ToolTip("F9 = Start/Stop Script", 0, 0)
        Sleep(2000)
        ToolTip("")
    EndIf
EndFunc   ;==>StartScript
Link to comment
Share on other sites

The least I can do is thank you for your kindness and for helping me...

Im sorry I seem a bit newbie its like my 3rd script in autoit and I couldnt make it work...

Yet, I wasnt able to get what was wrong with the code... Could you give me a little tip?

And sorry probably the best way to start in these forums would be to introduce myself in other section, ill do that right away

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...