【问题标题】:How to PixelSearch() faster?如何更快地进行 PixelSearch()?
【发布时间】:2015-12-19 07:31:41
【问题描述】:

使用PixelSearch() 和相对的鼠标移动,我让这个脚本将鼠标光标锁定在一个颜色上:

While 1 
    $pos = MouseGetPos()
    $coord = PixelSearch($pos[0]+80, $pos[1]+80, $pos[0]-80, $pos[1]-80, $color, 10,5)
    If IsArray($coord) = 1 Then
        Local $iX = $pos[0], $iY = $pos[1]
        If ($iX < $coord[0]) Then _MouseMoveRelative(1, 0);$iStepSize
        If ($iX > $coord[0]) Then  _MouseMoveRelative(-1, 0);$iStepSize
        If ($iY < $coord[1]) Then  _MouseMoveRelative(0, 1);$iStepSize
        If ($iY > $coord[1]) Then  _MouseMoveRelatsdive(0, -1);$iStepSize
        GUISetState()
    EndIf
WEnd

如果我增加步数,它会更快,但它会偏离目标。如果我减少,它会更慢但更准确。如何使这尽可能快?

【问题讨论】:

    标签: autoit


    【解决方案1】:

    这是最快的方法,因为鼠标会立即移动

    While 1 
        $pos = MouseGetPos()
        $coord = PixelSearch( $pos[0]-40, $pos[1]+40, $pos[0]+40, $pos[1]-40, $color, 10,5 )
        If IsArray($coord) = 1 Then
            Local $iX = $pos[0], $iY = $pos[1]
            If ($iX <> $coord[0]) Then _MouseMoveRelative($coord[0] - $iX,0)
            If ($iY <> $coord[1]) Then  _MouseMoveRelative(0,$coord[1] - $iY)
                ; GUISetState() This shouldn't be inside of a loop.
        EndIf
    Wend
    

    如果您仍然想要 $iStepSize,请这样做:

    While 1
        $pos = MouseGetPos()
        $coord = PixelSearch( $pos[0]-40, $pos[1]+40, $pos[0]+40, $pos[1]-40, $color, 10,5 )
        If IsArray($coord) = 1 Then
            Local $iX = $pos[0], $iY = $pos[1]
            Local $iXOffset = $coord[0] - $iX, $iYOffset = $coord[1] - $iY
    
            ToolTip( $coord[0] & " : " & $iX  & @CRLF & $coord[1] & " : " & $iY, $iX, $iY)
    
            If $iXOffset Then
                If Abs($iXOffset) < $iStepSize Then
                    $iMoving = $iXOffset
                Else
                    $iMoving = $iStepSize
                    If ($iXOffset) < 0 Then $iMoving *= -1
                EndIf
                _MouseMoveRelative($iMoving, 0)
    
            EndIf
    
    
            If $iYOffset Then
                If Abs($iYOffset) < $iStepSize Then
                    $iMoving = $iYOffset
                Else
                    $iMoving = $iStepSize
                    If ($iYOffset) < 0 Then $iMoving *= -1
                EndIf
                _MouseMoveRelative(0, $iMoving)
    
            EndIf
    
        EndIf
    Wend
    

    【讨论】:

    • 此脚本未经测试。它只是一个概念。从中学习,你一定会解决它。 :)
    • 只要增加步长,会更快。如果您将 step 增加到一个非常高的数字,它会像第一个示例一样立即执行。
    • 这是第一人称的,如果我增加步数,它会跳过很多
    • 与第一个完全相同,只需删除该工具提示即可。它可能会让你的屏幕闪烁
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-15
    • 2022-01-09
    • 2012-09-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多