Enlace original https://community.idera.com/database-tools/powershell/powertips/b/tips/posts/detecting-key-press-1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
Add-Type -AssemblyName WindowsBase Add-Type -AssemblyName PresentationCore # choose the abort key $key = [System.Windows.Input.Key]::LeftCtrl Write-Warning "PRESS $key TO ABORT!" do { $isCtrl = [System.Windows.Input.Keyboard]::IsKeyDown($key) if ($isCtrl) { Write-Host Write-Host "You pressed $key, so I am exiting!" -ForegroundColor Green break } Write-Host "." -NoNewline Start-Sleep -Milliseconds 100 } while ($true) |