我想像素搜索一个定义的区域。应用程序是 Bluestacks App Player:
蓝色矩形是 BlueStacks(它的位置可能会改变)。我使用ControlGetPos()
. 我只想在应用程序内的红色矩形中进行像素搜索。红色矩形的位置是307,628,355,675基于窗口信息和窗口坐标模式。但它不起作用。这是我的代码:
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