【问题标题】:Pixel search in defined area定义区域的像素搜索
【发布时间】:2017-09-22 21:19:27
【问题描述】:

我想对定义的区域进行像素搜索。应用程序是 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

【问题讨论】:

  • 您是如何获得搜索颜色的?我建议使用 printscreen 然后将其插入 Photoshop 并使用颜色工具获取颜色。如果您保存图像检查,请确保将其保存为 bmp
  • 还请重新格式化您的代码以 a) 包含所有相关的包含语句和 b) 包含可读的英文变量名称或至少 cmet 指出其内容/含义。此外,您可能希望使用 ImageSearch 的风格来查找该按钮。
  • 在红色矩形坐标的四个角上移动鼠标来验证它们。在你的动作之间睡一觉,然后转到左上角和右下角,看看你是否需要改变方式,你的 PixelCoordinates 正在被处理。有一些不同的方式,称为 PixelCoordMode。

标签: autoit bluestacks


【解决方案1】:

imagesearch 库似乎没有问题,问题是我使用 x64bit 运行 Windows 10。所以使用 x64 编译器(虽然它确实建议使用 x86 编译器)和管理员 previllige 编译它解决了这个问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-23
    • 1970-01-01
    相关资源
    最近更新 更多