Quick PixelSearch Testing

Post your working scripts, libraries and tools for AHK v1.1 and older
zeroun
Posts: 2
Joined: 12 Aug 2020, 09:38

Quick PixelSearch Testing

07 Jun 2021, 12:18

If anyone wants a quick pixelsearch tester, here's a function I come up with a while ago to make getting coordinates a lot faster. You can change your coordmode at the top, but I like using Client coords. Change the program variable at the top and attach clickTest() to a hotkey and if it finds the correct color at the coordinates it will play a windows sound and automatically copy it to your clipboard. Let me know if you have any questions.

Code: Select all

Global program = "enter program here"
Global PixelTest = 0
 
clickTest(){
    
    CoordMode Pixel Client
    CoordMode Mouse Client
        ;------------------------------------------------Select Color-------------------------------------------------
    Loop
    {
        mousegetpos, x, y
        PixelGetColor,Selected_Color,%x%,%y%, Fast RGB
        tooltip, RButton Select Color - %Selected_Color% , (x + 20), (y + 20), 1
        If (GetKeyState("RButton", "P")){
            break
        } 
    }
    KeyWait, RButton, L
    MouseGetPos,tpx,tpy
    PixelGetColor,Selected_Color,%tpx%,%tpy%, Fast RGB
    Tooltip,
    
    ;------------------------------------------------Select Top Left---------------------------------------------
    Loop{
        mousegetpos, x, y
        tooltip, Select Top Left %x% - %y%, (x + 20), (y + 20), 1
        If (GetKeyState("RButton", "P")){
            break
        } 
                ;Sleep 200
    }
    KeyWait, RButton, L
    MouseGetPos,tlx,tly
    Tooltip,
    ;------------------------------------------------Select Bottom Right-----------------------------------------
    
    Loop{
        mousegetpos, x, y
        tooltip, Select Bottom Right %x% - %y%, (x + 20), (y + 20), 1
        If (GetKeyState("RButton", "P")){
            break
        } 
                    ;Sleep 200
    }
    KeyWait, RButton, L
    MouseGetPos,brx,bry
    Tooltip,
    
    ;------------------------------------------------Pixel Color Test-------------------------------------------
    
    Loop{
        
        if(PixelTest < 19){
            PixelSearch, x, y, %tlx%, %tly%, %brx%, %bry%, %Selected_Color%, 1, Fast RGB
            if(ErrorLevel = 0){
                PixelTest++
                Tooltip, Successes - %PixelTest%
                ;WinActivate %program%
                ;WinWait %program%
            }
            if(ErrorLevel = 1){
                MsgBox, Can't find it, select new color
                PixelTest := 0
                WinActivate %program%
                WinWait %program%
                Loop
                {
                    mousegetpos, x, y
                    PixelGetColor,Selected_Color,%x%,%y%, Fast RGB
                    tooltip, RButton Select Color - %Selected_Color% , (x + 20), (y + 20), 1
                    If (GetKeyState("RButton", "P")){
                        break
                    } 
                }
                KeyWait, RButton, L
                MouseGetPos,tpx,tpy
                PixelGetColor,Selected_Color,%tpx%,%tpy%, Fast RGB
                Tooltip,
            }
        }
        if(PixelTest >= 19){
            Tooltip, 
            ;currentTask := "Tested the color " Selected_Color " successfully"
            SoundPlay, *-1
            Clipboard :=
            Clipboard = PixelSearch, x, y, %tlx%, %tly%, %brx%, %bry%, %Selected_Color%, 1, Fast RGB
            PixelTest := 0
            break
        }
    }
    
    F7::
    clickTest()
    return
    
    F12::
    ExitApp
}
Last edited by gregster on 07 Jun 2021, 12:30, edited 1 time in total.
Reason: Topic moved from 'AutoHotkey v2 Scripts and Functions' - I don't think this is v2 code...

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: yanjujino1 and 116 guests