我想在基于用户输入的每个循环"$wshell.SendKeys('M1 ABCD')“中,将M后面的数字递增1。第一个循环将输入"M1 ABCD",第二个"M2 ABCD",第三个"M3 ABCD“,直到脚本达到用户输入的请求循环数。
这是脚本的一小部分(不包括前置请求)
Param(
[Parameter(
Mandatory=$true,
Position=0,
HelpMessage="how many times do you want to run?")
]
$Number
)
$i = 0
while($i -lt $number){ #Number of times the loop repeats
Write-host "Loop run #$($i + 1)"
[Clicker]::LeftClickAtPoint(744,277)
$wshell.SendKeys('{DOWN}')
$wshell.SendKeys('{ENTER}')
$wshell.SendKeys('{TAB}')
Sleep -Milliseconds 600
$wshell.SendKeys('M1 ABCD')
$wshell.SendKeys('{DOWN}')
$wshell.SendKeys('{ENTER}')
$i++
}发布于 2021-03-27 22:59:50
试试这个:
Param(
[Parameter(
Mandatory=$true,
Position=0,
HelpMessage="how many times do you want to run?")
]
$Number
)
$i = 1
while($i -le $number){ #Number of times the loop repeats
Write-host "Loop run #$($i)"
[Clicker]::LeftClickAtPoint(744,277)
$wshell.SendKeys('{DOWN}')
$wshell.SendKeys('{ENTER}')
$wshell.SendKeys('{TAB}')
Sleep -Milliseconds 600
$wshell.SendKeys("M$i ABCD")
$wshell.SendKeys('{DOWN}')
$wshell.SendKeys('{ENTER}')
$i++
}请注意,我已经从1而不是0开始循环,并做了一些相应的调整。每次执行to循环时,都会计算双引号内的$i。
https://stackoverflow.com/questions/66827325
复制相似问题