Adam
Adam

Reputation: 3013

Set what Console.ReadKey gets with Console.SetIn?

I know you can do Console.SetIn(new StringReader("new input")); and then Console.ReadLine(); will return "new input" but is there a way to do this for Console.ReadKey()?

Upvotes: 1

Views: 708

Answers (2)

Hans Passant
Hans Passant

Reputation: 942448

No, Console.ReadKey() uses the native console API, ReadConsoleInput() to read input. You can't redirect that.

Other than by the obvious way, write a public static method that calls ReadKey() unless you want to return something else.

Upvotes: 1

steinar
steinar

Reputation: 9673

I believe you would rather want Console.Read() as ReadKey waits for a keystroke while Read just reads the next character.

Upvotes: 0

Related Questions