Windows Powershell '总是返回$true -我做错了什么?



问题几乎说明了一切。我有一个简单的脚本(下面),但IF不会合作。即使值不匹配,它的计算结果也总是为true。谢谢你的建议。

Add-Type -AssemblyName System.Windows.Forms
$pos = [System.Windows.Forms.Cursor]::Position
$x = $pos.X
$y = $pos.Y
while ($true)
{

Write-Host "on loop strt: x = $($x), y = $($y)"
$check = (($x -eq $pos.X) -and ($y -eq $pos.Y))
write-host $check
if (($x -eq $pos.X) -and ($y -eq $pos.Y))
{
for ($i = 0; $i -lt 2500; $i++)
{
$pos = [System.Windows.Forms.Cursor]::Position
$x = ($pos.X % 1024) + 1
$y = ($pos.Y % 768) + 1
[System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point($x, $y)
for ($d = 0; $d -lt 1000; $d++) {} #add a little delay
}
}
Write-Host "On loop exit: x = $($x), y = $($y)"
Start-Sleep -Seconds 5
$pos = [System.Windows.Forms.Cursor]::Position
$x = $pos.X
$y = $pos.Y
}

Issue似乎试图直接与pos.X和pos.Y进行比较——我添加了两个变量$a和$b进行比较。

Add-Type -AssemblyName System.Windows.Forms
$pos = [System.Windows.Forms.Cursor]::Position
$x = $pos.X
$y = $pos.Y
$a = $x
$b = $y
while ($true)
{
if ($x -eq $a -and $y -eq $b)
{
for ($i = 0; $i -lt 2500; $i++)
{
$pos = [System.Windows.Forms.Cursor]::Position
$x = [int]($pos.X % 1024) + 1
$y = [int]($pos.Y % 768) + 1
[System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point($x, $y)
for ($d = 0; $d -lt 1000; $d++) {}
}
}
else 
{ 
$pos = [System.Windows.Forms.Cursor]::Position
$x = $pos.X
$y = $pos.Y
$a = $x
$b = $y
}
Start-Sleep -Seconds 5
$pos = [System.Windows.Forms.Cursor]::Position
$x = [int]$pos.X
$y = [int]$pos.Y
}

相关内容

  • 没有找到相关文章

最新更新