如何更快地使用PixelSearch()



使用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

如果我增加步数,它会更快,但它会偏离目标。如果我减小,它会变慢,但更准确。怎样才能尽快完成?

这将是最快的方式,因为鼠标将立即移动

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

如果你仍然想要一个$ isstepsize,这样做:

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

相关内容

  • 没有找到相关文章

最新更新