Knu*_*ger 96
这是我使用的.
Write-Host -NoNewLine 'Press any key to continue...';
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
Run Code Online (Sandbox Code Playgroud)
小智 32
我创建了一个小的Powershell函数来模拟MSDOS pause.这可以处理运行Powershell ISE还是非ISE.(ReadKey并没有在PowerShell ISE中工作).运行Powershell ISE时,此功能会打开Windows MessageBox.这有时会令人困惑,因为MessageBox并不总是成为最重要的.无论如何,这里是:
用法:
pause "Press any key to continue"
功能定义:
Function pause ($message)
{
# Check if running Powershell ISE
if ($psISE)
{
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.MessageBox]::Show("$message")
}
else
{
Write-Host "$message" -ForegroundColor Yellow
$x = $host.ui.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
}
Run Code Online (Sandbox Code Playgroud)
Tre*_*van 19
查看.NET类的ReadKey()方法System.Console.我认为这会做你想要的.
http://msdn.microsoft.com/en-us/library/system.console.readkey(v=vs.110).aspx
例:
Write-Host -Object ('The key that was pressed was: {0}' -f [System.Console]::ReadKey().Key.ToString());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
119667 次 |
| 最近记录: |