选择不按回车?
Choice without pressing enter?
是否可以在用户只按数字而不需要按回车的情况下进行选择对话?
$options = [System.Management.Automation.Host.ChoiceDescription[]] @("&All", "&Client", "&Server")
$opt = $host.UI.PromptForChoice("Your Choice", "Files", $Options, 0)
在此示例中,用户必须按 A、Enter。我希望用户只需按 A.
您可以使用[system.console]::Readkey()
也许令人惊讶的是,您可以使用 choice
:
choice /c acs /m 'Your Choice'
switch ($LASTEXITCODE) {
1 { 'You chose "All".' }
2 { 'You chose "Client".' }
3 { 'You chose "Server".' }
}
是否可以在用户只按数字而不需要按回车的情况下进行选择对话?
$options = [System.Management.Automation.Host.ChoiceDescription[]] @("&All", "&Client", "&Server")
$opt = $host.UI.PromptForChoice("Your Choice", "Files", $Options, 0)
在此示例中,用户必须按 A、Enter。我希望用户只需按 A.
您可以使用[system.console]::Readkey()
也许令人惊讶的是,您可以使用 choice
:
choice /c acs /m 'Your Choice'
switch ($LASTEXITCODE) {
1 { 'You chose "All".' }
2 { 'You chose "Client".' }
3 { 'You chose "Server".' }
}