Eric Bergman-Terrell's Blog

PowerShell Tip: Prompt the User for a Key Press
August 21, 2011

How to prompt the user to type a particular key, and pause until that key is typed:

function Pause($Message)
{
Write-Host -NoNewLine $Message

do
{
$key = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
} while ($key.Character -ne 'Q')

Write-Host
}

...

Pause "Script Finished. Press Q to quit."
Keywords: PowerShell, Prompt, Key, Keystroke, Keypress

Reader Comments

Comment on this Blog Post

Recent Posts

TitleDate
EBTCalc (Android) Version 1.53 is now availableMay 19, 2024
Vault 3 Security EnhancementsOctober 24, 2023
Vault 3 is now available for Apple OSX M2 Mac Computers!September 18, 2023
Vault (for Desktop) Version 0.77 ReleasedMarch 26, 2023
EBTCalc (Android) Version 1.44 is now availableOctober 12, 2021
Vault (Desktop) Version 0.72 ReleasedOctober 6, 2021
EBT Compass is Now Available for Android DevicesJune 2, 2021