使用像素搜索和相对鼠标移动 我已将其锁定在屏幕上的颜色上,就像一个盒子。
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的新手,现在我很难过。 顺便说一下,我必须从那个剧本开始工作。 :(它可以&#39; 那是不是很难?
答案 0 :(得分: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