我可以从PowerShell脚本中显示一个简单的Visual Basic输入框,如下所示:
$null = [reflection.assembly]::loadwithpartialname("microsoft.visualbasic")
$input = [microsoft.visualbasic.interaction]::inputbox($question, "bla", $text)
但是,输入框窗口不会获得PowerShell窗口保留的焦点。
有没有办法将焦点放在输入框窗口上?
答案 0 :(得分:1)
您可以从作业中聚焦InputBox。
例如:
$null = [reflection.assembly]::loadwithpartialname("microsoft.visualbasic")
$activateWindow = {
$null = [reflection.assembly]::loadwithpartialname("microsoft.visualbasic")
$isWindowFound = $false
while(-not $isWindowFound) {
try {
[microsoft.visualbasic.interaction]::AppActivate($args[0])
$isWindowFound = $true
}
catch {
sleep -Milliseconds 100
}
}
}
$job = Start-Job $activateWindow -ArgumentList "Unique Title"
$input = [microsoft.visualbasic.interaction]::inputbox("What is your answer?", "Unique Title", "none")
Remove-Job $job -Force
Write-Host $input -ForegroundColor Yellow