I am learning about how to respond to keypresses in powerhsell and have been playing with ReadKey() I dont have much so far but the following sort of works. It sends a beep of a different pitch when a key is pressed, but, it just keeps looping the beep. I want to press a key have it beep once then return to a wait state waiting for the next key press. I’m sure the answer is simple to somone out there if you can help.
$ui=(get-host).ui $rui=$ui.rawui $key = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") while ($done=$true){ if ($key.virtualkeycode -eq -27) { $done=$false } if ($key.keydown) { # Left if ($key.virtualkeycode -eq 37) { [console]::Beep(300,300) } # Up if ($key.virtualkeycode -eq 38) { [console]::Beep(400,300) } # Right if ($key.virtualkeycode -eq 39) { [console]::Beep(500,300) } # Down if ($key.virtualkeycode -eq 40) { [console]::Beep(600,300) } } }
submitted by /u/kramit
[link] [comments]
The post Little Help with ReadKey() appeared first on How to Code .NET.