在循环中按热键可重新运行脚本,但不要等待 [英] Press hotkey to rerun script during a loop but don't wait for it
本文介绍了在循环中按热键可重新运行脚本,但不要等待的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
基本上,我有一个可以运行的脚本,它开始睡眠30分钟,然后再次循环并重新运行.我想知道是否有一种方法可以单击窗口,按热键,然后手动刷新它?
Basically I have a script that runs and it Start-Sleep for 30 minutes then loops around again and re-runs. I was wondering if there was a way where you could click on the window, press a hotkey, and have it just refresh manually?
while($true){
$data = @("device1", "device2")
ForEach ($server in $data) {
ping $server
start-sleep 1800
clear
}
}
推荐答案
通过其他方法,我发现以下内容使我可以检查屏幕上是否有任何按键,如果有按键,请中断该按键,但仍然会出现以下情况:睡眠状态.
I found through other methods that the below has allowed me to check the screen for any key press and break if there is one, but still be in a start-sleep status.
$timeout = New-TimeSpan -Minutes 30
$sw = [diagnostics.stopwatch]::StartNew()
while ($sw.elapsed -lt $timeout){
if ($host.UI.RawUI.KeyAvailable) {
$key = $host.UI.RawUI.ReadKey()
break
}
start-sleep -seconds 5
}
这篇关于在循环中按热键可重新运行脚本,但不要等待的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文