$continue = $true
while($continue)
{
if ([console]::KeyAvailable)
{
echo "Toggle with F12";
$x = [System.Console]::ReadKey()
switch ( $x.key)
{
F12 { $continue = $false }
}
}
else
{
$wsh = New-Object -ComObject WScript.Shell
$wsh.SendKeys('{CAPSLOCK}')
sleep 1
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($wsh)| out-null
Remove-Variable wsh
}
}
答案 0 :(得分:1)
$key = [console]::ReadKey()
write-host $key.key
if ($key.Key -eq '27') {
"Pressed Esc"
Do something
}
答案 1 :(得分:0)
感谢HariHaran的快速回答! 这是您使用Powershell中的Esc键关闭记事本的方法
R