Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Read One Character at a time

$
0
0

This seems trivial, but I can't figure it out. Is there a native way or a .NET method to get one character at a time?

I want to take in numbers or characters from the console and perform calculations depending on what the character is. Like so:

PS C:\Users\me\> Main.ps1
L
Turned Left
R
Turned Right
R
Turned Right
R
Turned Right
L
Turned Left
-
Goodbye
PS C:\Users\me\>

which would come from a program like this:

do{
$key = Read-Char
if($key -eq "R"){Write-Host "Turned Right"}
if($key -eq "L"){Write-Host "Turned Left"}
}while($key -ne "-")

Thanks.


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>