Pixel search in defined area

1k views Asked by At

I want to pixel search a defined area. Application is Bluestacks App Player:

enter image description here

Blue rectangle is BlueStacks (its position may change). I get the position using ControlGetPos(). I only want to pixel search in red rectangle inside the app. Position of red rectangle is 307,628,355,675 based on window info with windows coordinate mode. But It's not working. Here's my code :

HotKeySet("{F2}", "mulai")
HotKeySet("{F3}", "berhenti")

Global $lokasi[2]
Global $warna
Global $penghitung
Global $nyala
Global $title = "BlueStacks App Player"
Global $hwnd = WinGetHandle($title)
Global $BSpos

Func berhenti()
    Exit
EndFunc   ;==>berhenti

Func getPos()
    $aPos = ControlGetPos($title, "", "[CLASS:BlueStacksApp; INSTANCE:1]")
    $tPoint = DllStructCreate("int X;int Y")
    DllStructSetData($tPoint, "X", $aPos[0])
    DllStructSetData($tPoint, "Y", $aPos[1])
    _WinAPI_ClientToScreen(WinGetHandle(WinGetTitle($title)), $tPoint)

    $BSpos[0] = DllStructGetData($tPoint, "X")
    $BSpos[1] = DllStructGetData($tPoint, "Y")
EndFunc   ;==>getPos

Func mulai()
    $nyala = 1
    While $nyala = 1
        $pos = WinGetPos($hwnd)

        WinActivate($hwnd)
        $lokasi = PixelSearch($BSpos[0] , $BSpos[1], $BSpos[0] + $BSpos[2], $BSpos[1] + $BSpos[3], 0x0185B3)
        MouseMove($lokasi[0], $lokasi[1], 0)
        Sleep(200)
        If @error Then
            $penghitung = $penghitung + 1
        EndIf
        If $penghitung > 5 Then
            $nyala = 0
        EndIf
    WEnd
EndFunc   ;==>mulai

While 1
    Sleep(200)
WEnd
1

There are 1 answers

0
Rikudo Pain On BEST ANSWER

It seems there's nothing wrong with the imagesearch library, the problem is I running windows 10 using x64bit. So compiling it using x64 compiler (while it really suggest to use x86 compiler) with administrator previllige solved the problem.