I have a class that accepts input via TextReader and allows the class to receive input from either the console or a text field.
Below is a very simple example of what I'm trying to do:
using System.IO; class TestReader() { public TextReader CurrentStream { get; } public void SetInputStream( TextReader reader) { Reader = reader; } } class Program { static void Main( string[] args ) { TestReader rdr = new TestReader(); rdr.SetInputStream(Console.In); var input = (char)rdr.CurrentStream.Read(); Console.WriteLine( "You selected: " + input ); } }
How to change the above to implement ReadKey() , since the Read() method in the above example continues to accept input until the Enter key is pressed? I would like to implement ReadKey () so that it only accepts one keystroke.
Thanks.
** EDIT **
To clarify the situation, I am looking to implement ReadKey () without using Console.ReadKey (). Iβm not sure if this is possible because Google is not doing anything yet.
source share