0
while(true)
{
    var cki = Console.ReadKey(true);
    Console.WriteLine(cki.Key);
}

This code works when i run it from cmd/powershell, but doesn't work from git bash. This is the exception:

Unhandled exception. System.InvalidOperationException: Cannot read keys when either application does not have a console or when console input has been redirected. Try Console.Read.

The approach suggested from the exception is to use Console.Read method but it works very different from ReadKey. So how can I run a .net core console app from git bash, press 'down arrow', 'up arrow', or whatever key I press and get info for the key pressed immediately in my application?

  • I think `ReadKey` is the only option – Vivek Nuna Jun 19 '20 at 13:02
  • Does this answer your question? [Why ReadKey throws exception while running a .net-core console app from Git Bash?](https://stackoverflow.com/questions/62469201/why-readkey-throws-exception-while-running-a-net-core-console-app-from-git-bash) – Vivek Nuna Jun 19 '20 at 13:07
  • The question you are referencing is mine, so obviously not. –  Jun 19 '20 at 13:28
  • Take a look at https://stackoverflow.com/questions/46655517/why-is-net-core-handling-readkey-differently-on-raspbian as well. There's some fundamental differences between a Linux terminal (I am assuming that's what git bash is close to) and a Windows terminal. – omajid Jun 19 '20 at 16:20

0 Answers0